private static string GetFormatedText(EF6.PromotionPaymentFactor target, string[] textField, string textFormatString) { for (int i = 0; i < textField.Length; i++) { PropertyInfo pi = target.GetType().GetProperty(textField[i]); textFormatString = textFormatString.Replace("{" + i.ToString() + "}", pi != null ? pi.GetValue(target, null).ToString() : string.Empty); } return(textFormatString); }
/// <summary> /// Get a EF6.PromotionPaymentFactor object from the database using the given PaymentFactorId /// </summary> /// <param name="paymentFactorId">The primary key value</param> /// <returns>A EF6.PromotionPaymentFactor object</returns> public static EF6.PromotionPaymentFactor Get(Guid paymentFactorId) { EF6.PromotionPaymentFactor result = null; using (var ctx = new EF6.RT2020Entities()) { result = ctx.PromotionPaymentFactor.Where(x => x.PaymentFactorId == paymentFactorId).AsNoTracking().FirstOrDefault(); } return(result); }
/// <summary> /// Get a EF6.PromotionPaymentFactor object from the database using the given QueryString /// </summary> /// <param name="paymentFactorId">The primary key value</param> /// <returns>A EF6.PromotionPaymentFactor object</returns> public static EF6.PromotionPaymentFactor Get(string whereClause) { EF6.PromotionPaymentFactor result = null; using (var ctx = new EF6.RT2020Entities()) { result = ctx.PromotionPaymentFactor .SqlQuery(string.Format("Select * from PromotionPaymentFactor Where {0}", whereClause)) .AsNoTracking() .FirstOrDefault(); } return(result); }
private bool Save() { bool result = false; if (Verify() && !IsDuplicated()) { if (_CampaignId == Guid.Empty) { #region EidtMode.Add: 多 Workplace using (var ctx = new EF6.RT2020Entities()) { using (var scope = ctx.Database.BeginTransaction()) { try { var list = cbxWorkplace.GetCheckedComboView(); for (int i = 0; i < list.Items.Count; i++) { var chk = cbxWorkplace.GetCheck(i); if (cbxWorkplace.GetCheck(i)) { var row = (KeyValuePair <Guid, string>)list.Items[i]; var item = new EF6.PromotionPaymentFactor(); item = new EF6.PromotionPaymentFactor(); item.PaymentFactorId = Guid.NewGuid(); item.CreatedBy = ConfigHelper.CurrentUserId; item.CreatedOn = DateTime.Now; item.Retired = false; item.WorkplaceId = row.Key; if ((Guid)cboTender.SelectedValue != Guid.Empty) { item.TypeId = (Guid)cboTender.SelectedValue; } item.EventCode = txtEventCode.Text; item.FactorRate = (txtFactorRate.Text.Length == 0) ? 0 : Convert.ToDecimal(txtFactorRate.Text); item.StartOn = dtpStartDate.Value; item.EndOn = dtpEndDate.Value; item.ModifiedBy = ConfigHelper.CurrentUserId; item.ModifiedOn = DateTime.Now; ctx.PromotionPaymentFactor.Add(item); ctx.SaveChanges(); } } scope.Commit(); result = true; } catch (Exception ex) { scope.Rollback(); } } } #endregion } else { #region EditMode.Edit: 單 Wokrplace using (var ctx = new EF6.RT2020Entities()) { var item = ctx.PromotionPaymentFactor.Find(_CampaignId); if (item != null) { if ((Guid)cboWorkplace.SelectedValue != Guid.Empty) { item.WorkplaceId = (Guid)cboWorkplace.SelectedValue; } if ((Guid)cboTender.SelectedValue != Guid.Empty) { item.TypeId = (Guid)cboTender.SelectedValue; } item.EventCode = txtEventCode.Text; item.FactorRate = (txtFactorRate.Text.Length == 0) ? 0 : Convert.ToDecimal(txtFactorRate.Text); item.StartOn = dtpStartDate.Value; item.EndOn = dtpEndDate.Value; item.ModifiedBy = ConfigHelper.CurrentUserId; item.ModifiedOn = DateTime.Now; ctx.SaveChanges(); result = true; } } #endregion } } return(result); }