public bool DeleteParameters(DataTable dvRecords, string family_cd) { bool _status = false; foreach (DataRow dr in dvRecords.Rows) { try { if (family_cd.IsNotNullOrEmpty() && dr["PARAMETER_CD"].ToString() != "") { TOOL_PARAMETER toolp = (from o in DB.TOOL_PARAMETER where o.FAMILY_CD == family_cd && o.PARAMETER_CD == dr["PARAMETER_CD"].ToString() select o).SingleOrDefault <TOOL_PARAMETER>(); if (toolp != null) { DB.TOOL_PARAMETER.DeleteOnSubmit(toolp); DB.SubmitChanges(); } toolp = null; _status = true; } } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); _status = true; } catch (Exception ex) { _status = false; throw ex.LogException(); } } return(_status); }
public bool UpdateToolAdmin(ToolAdminModel tooladm) { bool _status = false; tooladm.Status = ""; try { if (tooladm.Mode == OperationMode.AddNew) { TOOL_FAMILY toolf = (from o in DB.TOOL_FAMILY where o.FAMILY_CD == tooladm.FAMILY_CD select o).FirstOrDefault <TOOL_FAMILY>(); if (toolf == null) { try { toolf = new TOOL_FAMILY(); toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.ROWID = Guid.NewGuid(); DB.TOOL_FAMILY.InsertOnSubmit(toolf); DB.SubmitChanges(); toolf = null; tooladm.Status = PDMsg.SavedSuccessfully; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.DeleteOnSubmit(toolf); } } else if (toolf != null) { try { toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; if (tooladm.ImageChanged == true) { toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.UPDATED_BY = null; //toolf.UPDATED_DATE = null; DB.SubmitChanges(); toolf = null; tooladm.Status = PDMsg.SavedSuccessfully; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolf); } } toolf = null; } else if (tooladm.Mode == OperationMode.Edit) { TOOL_FAMILY toolf = (from o in DB.TOOL_FAMILY where o.FAMILY_CD == tooladm.FAMILY_CD select o).FirstOrDefault <TOOL_FAMILY>(); if (toolf != null) { try { if (tooladm.ImageChanged == true) { toolf.FAMILY_CD = tooladm.FAMILY_CD; toolf.FAMILY_NAME = tooladm.FAMILY_NAME; toolf.TOOL_PATH = tooladm.File_Name; if (tooladm.picture != null) { toolf.PICTURE = tooladm.picture.ToArray(); } DB.SubmitChanges(); tooladm.Status = PDMsg.SavedSuccessfully; } //toolf.ENTERED_BY = userInformation.UserName; //toolf.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolf.UPDATED_BY = null; //toolf.UPDATED_DATE = null; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); tooladm.Status = PDMsg.SavedSuccessfully; } catch (Exception ex) { ex.LogException(); DB.TOOL_FAMILY.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolf); } } } foreach (DataRowView dr in tooladm.DVToolParameter) { if (dr["PARAMETER_CD"].ToString() != "") { TOOL_PARAMETER toolp = (from o in DB.TOOL_PARAMETER where o.FAMILY_CD == tooladm.FAMILY_CD && o.PARAMETER_CD == dr["PARAMETER_CD"].ToString() select o).SingleOrDefault <TOOL_PARAMETER>(); if (toolp == null) { try { toolp = new TOOL_PARAMETER(); toolp.FAMILY_CD = tooladm.FAMILY_CD; toolp.PARAMETER_CD = dr["PARAMETER_CD"].ToString(); toolp.PARAMETER_NAME = dr["PARAMETER_NAME"].ToString(); toolp.X_COORDINATE = dr["X_COORDINATE"].ToValueAsString().ToIntValue(); toolp.Y_COORDINATE = dr["Y_COORDINATE"].ToValueAsString().ToIntValue(); toolp.DATATYPE = dr["DATATYPE"].ToValueAsString().ToIntValue(); toolp.DEFAULT_VALUE = dr["DEFAULT_VALUE"].ToString(); toolp.DEFAULT_VISIBLE = dr["DEFAULT_VISIBLE"].ToValueAsString().ToIntValue(); //toolp.ENTERED_BY = userInformation.UserName; //toolp.ENTERED_DATE = userInformation.Dal.ServerDateTime; toolp.ROWID = Guid.NewGuid(); DB.TOOL_PARAMETER.InsertOnSubmit(toolp); DB.SubmitChanges(); toolp = null; //ToolAdm.Status = "Record inserted successfully."; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { ex.LogException(); DB.TOOL_PARAMETER.DeleteOnSubmit(toolp); } } else if (toolp != null) { try { toolp.FAMILY_CD = tooladm.FAMILY_CD; toolp.PARAMETER_CD = dr["PARAMETER_CD"].ToString(); toolp.PARAMETER_NAME = dr["PARAMETER_NAME"].ToString(); toolp.X_COORDINATE = dr["X_COORDINATE"].ToValueAsString().ToIntValue(); toolp.Y_COORDINATE = dr["Y_COORDINATE"].ToValueAsString().ToIntValue(); toolp.DATATYPE = dr["DATATYPE"].ToValueAsString().ToIntValue(); toolp.DEFAULT_VALUE = dr["DEFAULT_VALUE"].ToString(); toolp.DEFAULT_VISIBLE = dr["DEFAULT_VISIBLE"].ToValueAsString().ToIntValue(); //toolp.ENTERED_BY = userInformation.UserName; //toolp.ENTERED_DATE = userInformation.Dal.ServerDateTime; //toolp.UPDATED_BY = null; //toolp.UPDATED_DATE = null; DB.SubmitChanges(); toolp = null; //ToolAdm.Status = "Record inserted successfully."; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { DB.TOOL_PARAMETER.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, toolp); ex.LogException(); } } toolp = null; } } DeleteParameters(tooladm.DTDeletedRecords, tooladm.FAMILY_CD); _status = true; } catch (System.Data.Linq.ChangeConflictException) { DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges); } catch (Exception ex) { throw ex.LogException(); } return(_status); }