private void Delete() { using (var ctx = new EF6.RT2020Entities()) { var oSupplier = ctx.Supplier.Find(_SupplierId); if (oSupplier == null) { switch ((int)oSupplier.Status) { case (int)EnumHelper.Status.Active: //2014.01.04 paulus: 如果 Supplier.Status = Active 設為 Deleted + Retired oSupplier.Status = Convert.ToInt32(EnumHelper.Status.Deleted.ToString("d")); oSupplier.Retired = true; oSupplier.RetiredOn = DateTime.Now; oSupplier.RetiredBy = ConfigHelper.CurrentUserId; break; case (int)EnumHelper.Status.Draft: //2014.01.04 paulus: 如果 Supplier.Status = Draft 可以直接刪除 string sql = "SupplierId = '" + oSupplier.SupplierId.ToString() + "'"; SupplierSmartTagEx.Delete(oSupplier.SupplierId); SupplierContactEx.Delete(oSupplier.SupplierId); SupplierAddressEx.Delete(oSupplier.SupplierId); ctx.Supplier.Remove(oSupplier); break; } ctx.SaveChanges(); } } }
private void LoadSmartTagValues() { foreach (Control Ctrl in Controls) { if (Ctrl.Name.Contains("SmartTag") && !Ctrl.Name.StartsWith("lbl")) { SupplierSmartTagEx.LoadSmartTagValue(_SupplierId, Ctrl); } } }
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 void GetSmartValue(Guid supplierId, Control Ctrl) { string sql = "SupplierId = '" + supplierId.ToString() + "' AND TagId = '{0}'"; string key = "SmartTag"; Guid tagId = Guid.Empty; if (Ctrl != null && Ctrl.Name.Contains(key)) { if (Ctrl.Tag != null) { tagId = (Guid)Ctrl.Tag; var oTag = SupplierSmartTagEx.Get(supplierId, tagId); if (oTag != null) { if (Ctrl.GetType().Equals(typeof(TextBox))) { TextBox txtTag = Ctrl as TextBox; txtTag.Text = oTag.SmartTagValue; } if (Ctrl.GetType().Equals(typeof(MaskedTextBox))) { MaskedTextBox txtTag = Ctrl as MaskedTextBox; txtTag.Text = oTag.SmartTagValue; } if (Ctrl.GetType().Equals(typeof(ComboBox))) { var id = Guid.Empty; if (Guid.TryParse(oTag.SmartTagValue, out id)) { // 2020.12.28 paulus: 如果係 combo box,個 value = dbo.SmartTag_Options.OptionId ComboBox cboTag = Ctrl as ComboBox; //cboTag.Text = oTag.SmartTagValue; cboTag.SelectedValue = id; } } if (Ctrl.GetType().Equals(typeof(DateTimePicker))) { DateTimePicker dtpTag = Ctrl as DateTimePicker; //2014.01.08 paulus: 可以唔輸入 birthday,先決係要有 ShowCheckBox,然後根據 value //舊 code: dtpTag.Value = (oTag.SmartTagValue.Length == 0) ? DateTime.Now : Convert.ToDateTime(ReformatDateTime(oTag.SmartTagValue)); if (dtpTag.ShowCheckBox) { if (oTag.SmartTagValue.Length == 0) { dtpTag.Value = dtpTag.MinDate; dtpTag.Checked = false; } else { dtpTag.Value = Convert.ToDateTime(DateTimeHelper.ReformatDateTime(oTag.SmartTagValue)); dtpTag.Checked = true; } } else { dtpTag.Value = (oTag.SmartTagValue.Length == 0) ? dtpTag.MinDate : Convert.ToDateTime(DateTimeHelper.ReformatDateTime(oTag.SmartTagValue)); } } } } } }