public static EF6.Supplier GetBySupplierCode(string code) { EF6.Supplier result = null; using (var ctx = new EF6.RT2020Entities()) { result = ctx.Supplier.Where(x => x.SupplierCode == code).FirstOrDefault(); } return(result); }
public static EF6.Supplier GetBySupplierId(Guid supplierId) { EF6.Supplier result = null; using (var ctx = new EF6.RT2020Entities()) { result = ctx.Supplier.Find(supplierId); } return(result); }
public bool SaveGeneralData() { var result = false; try { using (var ctx = new EF6.RT2020Entities()) { #region save core data var item = ctx.Supplier.Find(_SupplierId); if (item == null) { #region add new dbo.Supplier item = new EF6.Supplier(); item.SupplierId = Guid.NewGuid(); item.SupplierCode = _SupplierCode; item.Status = (int)EnumHelper.Status.Active; //2014.01.04 paulus: 一開始就係 Active item.CreatedBy = ConfigHelper.CurrentUserId; item.CreatedOn = DateTime.Now; ctx.Supplier.Add(item); _SupplierId = item.SupplierId; #endregion } item.SupplierInitial = txtInitial.Text; item.SupplierName = txtName.Text; item.SupplierName_Chs = txtNameChs.Text; item.SupplierName_Cht = txtNameCht.Text; if ((Guid)cboMarketSector.SelectedValue != Guid.Empty) { item.MarketSectorId = (Guid)cboMarketSector.SelectedValue; } item.Remarks = txtRemarks.Text; if (ctx.Entry(item).State != EntityState.Added) { item.Status = Convert.ToInt32(EnumHelper.Status.Modified.ToString("d")); } item.ModifiedBy = ConfigHelper.CurrentUserId; item.ModifiedOn = DateTime.Now; ctx.SaveChanges(); #region log activity (Update) RT2020.Controls.Log4net.LogInfo(ctx.Entry(item).State == EntityState.Added ? RT2020.Controls.Log4net.LogAction.Create : RT2020.Controls.Log4net.LogAction.Update, item.ToString()); #endregion #endregion } #region SaveSmartTagValues foreach (Control Ctrl in Controls) { if (Ctrl.Name.Contains("SmartTag") && !Ctrl.Name.StartsWith("lbl")) { SupplierSmartTagEx.SaveSmartTagValue(_SupplierId, Ctrl); } } #endregion result = true; } catch (Exception ex) { result = false; } return(result); }
private bool Save() { var result = false; if (Verify() && IsValid()) { bool canSave = false, isNew = false; using (var ctx = new EF6.RT2020Entities()) { var item = ctx.Supplier.Find(_SupplierId); if (item == null) { item = new EF6.Supplier(); item.SupplierId = Guid.NewGuid(); item.SupplierCode = txtSupplierCode.Text.Trim(); item.Status = (int)EnumHelper.Status.Active; //2014.01.04 paulus: 一開始就係 Active item.CreatedBy = ConfigHelper.CurrentUserId; item.CreatedOn = DateTime.Now; ctx.Supplier.Add(item); _SupplierId = item.SupplierId; _SupplierCode = item.SupplierCode; } //item.SupplierInitial = general.txtInitial.Text; //item.SupplierName = general.txtName.Text; //item.SupplierName_Chs = general.txtNameChs.Text; //item.SupplierName_Cht = general.txtNameCht.Text; //item.AlternateSupplier = general.txtSmartTag1.Text; //item.MarketSectorId = new Guid(general.cboMarketSector.SelectedValue.ToString()); //item.Remarks = general.txtRemarks.Text; item.Status = ctx.Entry(item).State == EntityState.Added ? (int)EnumHelper.Status.Active : (int)EnumHelper.Status.Modified; item.ModifiedBy = ConfigHelper.CurrentUserId; item.ModifiedOn = DateTime.Now; ctx.SaveChanges(); //SaveSmartTagValue(_SupplierId); result = true; } #region general.SaveGeneralData if (tabGeneralLoaded) { if (_EditMode == EnumHelper.EditMode.Add) { general.SupplierId = _SupplierId; general.SupplierCode = _SupplierCode; } // result = general.SaveGeneralData(); } #endregion #region address.SaveAddressData if (tabAddressLoaded && result) { if (_EditMode == EnumHelper.EditMode.Add) { address.SupplierId = _SupplierId; } result = address.SaveAddressData(); } #endregion #region contact.SaveContctData if (tabContactLoaded && result) { if (_EditMode == EnumHelper.EditMode.Add) { contact.SupplierId = _SupplierId; } result = contact.SaveContctData(); } #endregion #region finance.SaveFinanceData if (tabFinancialLoaded && result) { if (_EditMode == EnumHelper.EditMode.Add) { finance.SupplierId = _SupplierId; } result = finance.SaveFinanceData(); } #endregion return(result); } else { return(false); } }