Hello community. I have a strict architecture, which i have to follow. I0m trying to implement insert operations, but really don´t know how to do it following this logic.
I have implemented the EditItem event, and the Save File also works, so i'm searching a similar operations to inserrt, creating an object when ID=0. Can you help me do this?
I have implemented the EditItem event, and the Save File also works, so i'm searching a similar operations to inserrt, creating an object when ID=0. Can you help me do this?
CommandItem events and Save in DB method:
if (e.CommandName == "EditItem")
{
try
{
string script = "function f(){openRadWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
e.Canceled = true;
int idtimesheet = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
ListagemTimesheet timesheet = listagembll.GetFileByID(idtimesheet);
EditTimesheet.Objecto = timesheet;
EditTimesheet.DataBind();
gvTimesheets.Rebind();
lblMessageOK.Text = "Registo adicionado com sucesso!";
}
catch (System.Exception)
{
//string mailSuporte = Config.ConfigurationsGP.ContactoSuporte;
//lblMessageErro.Text = (("Aconteceu um erro na gravação da informação. Tente de novo por favor.<br/> Caso se repita o erro contacte: "
// + mailSuporte));
}
}
if (e.CommandName == "InsertItem")
{
try
{
string script = "function f(){openRadWindow(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
e.Canceled = true;
int idtimesheet = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
ListagemTimesheet timesheet = listagembll.GetFileByID(idtimesheet);
EditTimesheet.Objecto = timesheet;
EditTimesheet.DataBind();
gvTimesheets.Rebind();
lblMessageOK.Text = "Registo adicionado com sucesso!";
}
catch (System.Exception)
{
string mailSuporte = Config.ConfigurationsGP.ContactoSuporte;
lblMessageErro.Text = (("Aconteceu um erro na gravação da informação. Tente de novo por favor.<br/> Caso se repita o erro contacte: "
+ mailSuporte));
}
}
//Save file in DB
public void SaveFile(object sender, EventArgs e)
{
ListagemTimesheet model = new ListagemTimesheet();
model.IDRecursoHumano = Convert.ToInt32(rdpInvestigadorE.Text);
model.IDEstadoTimesheet = Convert.ToInt32(rcbEstado.SelectedValue);
model.Observações = Obervaçoestxt.Text;
model.AssinaturaTimesheet = txtAssinaturaTimesheet.Text;
model.DataEnvio = DataEnvio.SelectedDate.Value;
if (Objecto.ID > 0)
{
model.ID = Convert.ToInt32(FileID.Text);
if (!string.IsNullOrEmpty(Ficheiro) && FileTipo != null)
{
model.Ficheiro = Path.GetFileNameWithoutExtension(Ficheiro); //está
model.FileTipo = Path.GetExtension(FileTipo);
model.FileContent = fileBytes;
}
if (!string.IsNullOrEmpty(FileID.Text) && Convert.ToInt32(FileID.Text) > 0)
{
model.ID = Convert.ToInt32(FileID.Text);
listagembll.UpdateFile(model);
}
else
{
}
}
else //Objecto.ID = 0
{
ListagemTimesheet novo = new ListagemTimesheet();
novo.IDRecursoHumano = Convert.ToInt32(rdpInvestigadorE.Text);
novo.IDEstadoTimesheet = Convert.ToInt32(rcbEstado.SelectedValue);
model.Observações = Obervaçoestxt.Text;
model.AssinaturaTimesheet = txtAssinaturaTimesheet.Text;
model.DataEnvio = DataEnvio.SelectedDate.Value;
}