private CRMCustomerIndustry GetSaveEntity() { var entity = new CRMCustomerIndustry(); if (string.IsNullOrEmpty(txtIndustryID.Text.Trim()) == false) { entity.IndustryID = int.Parse(txtIndustryID.Text.Trim()); } if (string.IsNullOrEmpty(txtIndustry.Text.Trim()) == false) { entity.Industry = txtIndustry.Text.Trim(); } return(entity); }
//---------------保存CRMCustomerIndustry--------------------------- public CRMCustomerIndustry Save(CRMCustomerIndustry entity) { if (this.dataCtx.Connection != null) { if (this.dataCtx.Connection.State == ConnectionState.Closed) { this.dataCtx.Connection.Open(); } } DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMCustomerIndustrys where t.IndustryID == entity.IndustryID select t; var obj = qry.SingleOrDefault(); if (obj != null) { this.CopyEntity(obj, entity); } else { this.CRMCustomerIndustrys.InsertOnSubmit(entity); } this.dataCtx.SubmitChanges(); tran.Commit(); return(entity); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }
private CRMCustomerIndustry GetSaveEntity() { var entity = new CRMCustomerIndustry(); if (string.IsNullOrEmpty(txtIndustryID.Text.Trim()) == false) entity.IndustryID = int.Parse(txtIndustryID.Text.Trim()); if (string.IsNullOrEmpty(txtIndustry.Text.Trim()) == false) entity.Industry = txtIndustry.Text.Trim(); return entity; }
//---------------保存CRMCustomerIndustry--------------------------- public CRMCustomerIndustry Save(CRMCustomerIndustry entity) { if (this.dataCtx.Connection != null) if (this.dataCtx.Connection.State == ConnectionState.Closed) this.dataCtx.Connection.Open(); DbTransaction tran = this.dataCtx.Connection.BeginTransaction(); dataCtx.Transaction = tran; try { var qry = from t in CRMCustomerIndustrys where t.IndustryID == entity.IndustryID select t; var obj = qry.SingleOrDefault(); if (obj != null) this.CopyEntity(obj, entity); else this.CRMCustomerIndustrys.InsertOnSubmit(entity); this.dataCtx.SubmitChanges(); tran.Commit(); return entity; } catch (Exception ex) { tran.Rollback(); throw ex; } finally { dataCtx.Connection.Close(); } }