Hello community!
I am using and following this Demo, and i want the exact same result for Insert and Update operations, my problem is that my architcture is totally different and i can't addapt it to the solution.
My main problem is in the update and insert command events.. i tried several ways but i have no idea on how to do it (the problem uses session and DataTable, which are not usefull for me)
I will also share a demo (non functional), if you are willing to take a better look see my architecture and Get methods. I am using 3 layers architecture
The frontend follows the telerik framework Command Item template, which creates the add and edit buttons, which should be triggered by the command events.
Thank you in advance!
I am using and following this Demo, and i want the exact same result for Insert and Update operations, my problem is that my architcture is totally different and i can't addapt it to the solution.
My main problem is in the update and insert command events.. i tried several ways but i have no idea on how to do it (the problem uses session and DataTable, which are not usefull for me)
I will also share a demo (non functional), if you are willing to take a better look see my architecture and Get methods. I am using 3 layers architecture
InsertCommand method:
protected void gvTimesheets_InsertCommand(object source, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
ViewEmissaoTimeSheetEdit userControl = (ViewEmissaoTimeSheetEdit)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
//Create new row in the DataSource
var editableItem = ((GridEditableItem)e.Item);
var timesheetID = (int)editableItem.GetDataKeyValue("ID"); //evaluate ID value
//WITH ERRORS, NEED HELP HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//Insert new values
Hashtable newValues = new Hashtable();
newValues["IDRecursoHumano"] = (userControl.FindControl("rdpInvestigador") as RadTextBox).Text;
newValues["IDEstadoTimesheet"] = (userControl.FindControl("rdbEstado") as RadComboBox).Text;
newValues["AssinaturaTimesheet"] = (userControl.FindControl("txtAssinaturaTimesheet") as RadTextBox).Text;
newValues["Observações"] = (userControl.FindControl("Obervaçoestxt") as RadTextBox).Text;
newValues["DataEnvio"] = (userControl.FindControl("DataEnvio") as RadDatePicker).SelectedDate.ToString();
newValues["FileContent"] = (userControl.FindControl("RadAsyncUpload1") as RadAsyncUpload).TargetFolder.ToString();
//make sure that unique primary key value is generated for the inserted roW
//NEED HELP
try
{
foreach (DictionaryEntry entry in newValues)
{
//NEED HELP
}
// SAVE CHANGES
}
catch (Exception ex)
{
e.Canceled = true;
}
}
//BLL methods "listagembll":
public List<ListagemTimesheet> GetAllFiles(int IDRecursoHumano = 0) ///filtros de pesquisa por investigador, include FKs
{
try
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
var query = lt.ListagemTimesheets.Include("RecursoHumano").Include("EstadoTimesheet").AsQueryable();
if (IDRecursoHumano > 0)
query = query.Where(a => a.IDRecursoHumano == IDRecursoHumano);
return query.ToList();
}
}
catch (Exception ex)
{
//log.Error("BLL => GetAllFiles:" + ex.Message);
return new List<ListagemTimesheet>();
}
}
// Save File
public int SaveFile(ListagemTimesheet model)
{
try
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
lt.ListagemTimesheets.AddObject(model);
lt.SaveChanges();
return model.ID;
}
}
catch (Exception ex)
{
//log.Error("BLL => SaveFile:" + ex.Message);
return 0;
}
}
/// Update File
public void UpdateFile(ListagemTimesheet model)
{
try
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
var result = lt.ListagemTimesheets.SingleOrDefault(b => b.ID == model.ID);
if (result != null)
{
result.IDEstadoTimesheet = model.IDEstadoTimesheet;
result.FileContent = model.FileContent;
result.Ficheiro = model.Ficheiro;
result.DataEnvio = model.DataEnvio;
result.FileTipo = model.FileTipo;
result.AssinaturaTimesheet = model.AssinaturaTimesheet;
result.Observações = model.Observações;
lt.SaveChanges();
}
}
}
catch (Exception ex)
{
//log.Error("BLL => UpdateFile:" + ex.Message);
}
}
public void InsertFile(ListagemTimesheet model)
{
try
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
var result = lt.ListagemTimesheets.SingleOrDefault(b => b.ID == model.ID);
if (result != null)
{
result.ID = model.ID;
result.IDRecursoHumano = model.IDRecursoHumano;
result.IDEstadoTimesheet = model.IDEstadoTimesheet;
result.FileContent = model.FileContent;
result.Ficheiro = model.Ficheiro;
result.DataEnvio = model.DataEnvio;
result.FileTipo = model.FileTipo;
result.AssinaturaTimesheet = model.AssinaturaTimesheet;
result.Observações = model.Observações;
lt.SaveChanges();
}
}
}
catch (Exception ex)
{
//log.Error("BLL => UpdateFile:" + ex.Message);
}
}
//DataTable model:
public partial class ListagemTimesheet
{
public int ID { get; set; }
public System.DateTime DataEnvio { get; set; }
public int IDRecursoHumano { get; set; }
public string AssinaturaTimesheet { get; set; }
public int IDEstadoTimesheet { get; set; }
public string Observações { get; set; }
public string Ficheiro { get; set; }
public string FileTipo { get; set; }
public byte[] FileContent { get; set; }
public virtual EstadoTimesheet EstadoTimesheet { get; set; }
public virtual RecursoHumano RecursoHumano { get; set; }
}
}
The frontend follows the telerik framework Command Item template, which creates the add and edit buttons, which should be triggered by the command events.
Frontend:
<CommandItemTemplate>
<telerik:RadButton CommandName="InitInsert" IsinEditmode="true" RenderMode="Lightweight" ID="AddNewRecordButton" Text="Adicionar nova versão" ToolTip="Adicionar versão" runat="server" style="background:none; border:none; color:green;" NavigateUrl="~/Views/Projectos/Equipa/ViewEmissaoTimeSheetEdit.ascx" CommandArgument="ID">
<Icon PrimaryIconCssClass="rbAdd"></Icon>
</telerik:RadButton>
<telerik:RadButton CommandName="Rebind" RenderMode="Lightweight" ID="Rebindbutton" Text="Atualizar lista" ToolTip="Atualizar a lista" runat="server" style="background:none; border:none; color:darkblue;" >
<Icon PrimaryIconCssClass=" rbRefresh"></Icon>
</telerik:RadButton>
</CommandItemTemplate>
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="PushButton" ItemStyle-ForeColor="Black">
</telerik:GridEditCommandColumn>
<EditFormSettings UserControlName="~/Views/ViewEmissaoTimeSheetEdit.ascx" EditFormType="WebUserControl" >
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
Thank you in advance!
Attachments
Last edited: