public ActionResult PromotionInfo(int?id) { if (Session["login"] is null) { return(RedirectToAction("Login")); } int idRole = ((USER)Session["login"]).IdRole; if (idRole != 1) { return(RedirectToAction("Index")); } PROMOTION promotion = new PROMOTION(); if (id != null) { using (THUONGMAIDIENTUEntities db = new THUONGMAIDIENTUEntities()) { promotion = db.PROMOTIONs.Where(x => x.IdPromotion == id).FirstOrDefault(); if (promotion is null) { return(HttpNotFound()); } } } return(View(promotion)); }
public bool UpdatePROMOTION(PROMOTION PROMOTION) { string sql = @"sp_promotion_UPDATE"; string sql_dta = @"sp_promotionproduct_UPDATE"; string sql_del = @"sp_promotionproduct_DELETE"; object[] obj = { "@ProMID", PROMOTION.ProMID, "@ProMStartDate", PROMOTION.ProMStartDate, "@ProMEndDate", PROMOTION.ProMEndDate, "@Discount", PROMOTION.Discount }; object[] del = { "@ProMID", PROMOTION.ProMID }; using (TransactionScope ts = new TransactionScope()) { try { Db.Update(sql, obj); Db.Delete(sql_del, del); foreach (var ls in PROMOTION.PRODUCT) { object[] objs = { "@PrdID", ls.PrdID, "@ProMID", PROMOTION.ProMID }; try { Db.Insert(sql_dta, objs); } catch { return(false); } } ts.Complete(); return(true); } catch { return(false); } } }
public bool InsertPROMOTION(PROMOTION PROMOTION) { string sql = @"sp_promotion_INSERT"; string sql_dta = @"sp_promotionproduct_INSERT"; object[] obj = { "@ProMStartDate", PROMOTION.ProMStartDate, "@ProMEndDate", PROMOTION.ProMEndDate, "@Discount", PROMOTION.Discount }; using (TransactionScope ts = new TransactionScope()) { string retID = Db.InsertReturnID(sql, obj); if (retID != null) { foreach (var ls in PROMOTION.PRODUCT) { object[] objs = { "@PrdID", ls.PrdID, "@ProMID", retID }; try { Db.Insert(sql_dta, objs); } catch { return(false); } } ts.Complete(); return(true); } else { return(false); } } }
private List <PROMOTION> MapPROMOTION(DataTable dt) { List <PROMOTION> rs = new List <PROMOTION>(); for (int i = 0; i < dt.Rows.Count; i++) { PROMOTION obj = new PROMOTION(); if (dt.Columns.Contains("ID")) { obj.ID = (dt.Rows[i]["ID"].ToString()); } if (dt.Columns.Contains("Name_Promotion")) { obj.Name_Promotion = dt.Rows[i]["Name_Promotion"].ToString(); } if (dt.Columns.Contains("Refdate")) { obj.Refdate = DateTime.Parse(dt.Rows[i]["Refdate"].ToString()); } if (dt.Columns.Contains("RefType")) { obj.RefType = int.Parse(dt.Rows[i]["RefType"].ToString()); } if (dt.Columns.Contains("StartDate")) { obj.StartDate = DateTime.Parse(dt.Rows[i]["StartDate"].ToString()); } if (dt.Columns.Contains("StopDate")) { obj.StopDate = DateTime.Parse(dt.Rows[i]["StopDate"].ToString()); } if (dt.Columns.Contains("Active")) { obj.Active = bool.Parse(dt.Rows[i]["Active"].ToString()); } if (dt.Columns.Contains("CreateBy")) { obj.CreateBy = dt.Rows[i]["CreateBy"].ToString(); } if (dt.Columns.Contains("Createdate")) { obj.Createdate = DateTime.Parse(dt.Rows[i]["Createdate"].ToString()); } if (dt.Columns.Contains("ModifyBy")) { obj.ModifyBy = dt.Rows[i]["ModifyBy"].ToString(); } if (dt.Columns.Contains("ModifyDate")) { obj.ModifyDate = DateTime.Parse(dt.Rows[i]["ModifyDate"].ToString()); } rs.Add(obj); } return(rs); }
private void barLargeButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (gridView1.FocusedRowHandle >= 0) { string id = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString(); PROMOTION objpromotion = new PROMOTION(); objpromotion = new PROMOTIONController().PROMOTION_Get(id); frmChinhSuaKhuyenMai frm = new frmChinhSuaKhuyenMai(this, objpromotion); frm.ShowDialog(); } }
private void gridControl1_DoubleClick(object sender, EventArgs e) { if (gridView1.FocusedRowHandle >= 0) { string id = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString(); PROMOTION objpromotion = new PROMOTION(); objpromotion = new PROMOTIONController().PROMOTION_Get(id); frmChinhSuaKhuyenMai frm = new frmChinhSuaKhuyenMai(this, objpromotion); frm.ShowDialog(); } }
public ActionResult EditPromotion(string ProMID) { if (Session["S_EmpID"] != null && Session["S_EmpFname"] != null) { PROMOTION pm = new PROMOTION(); pm.ProMID = ProMID; return(View(pm)); } else { return(RedirectToAction("Login2", "Account")); } }
public ActionResult EditPromotion(PROMOTION model) { if (Session["S_EmpID"] != null) { var resolveRequest = HttpContext.Request; resolveRequest.InputStream.Seek(0, SeekOrigin.Begin); string jsonString = new StreamReader(resolveRequest.InputStream).ReadToEnd(); if (jsonString != null) { if (Session["S_EmpID"].ToString() != null) { dynamic jArr2 = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString); foreach (dynamic item in jArr2) { foreach (var pr in item.PROMOTION) { model.ProMStartDate = pr.ProMStartDate; model.ProMEndDate = pr.ProMEndDate; model.Discount = pr.Discount; model.ProMID = pr.ProMID; } foreach (var rs in item.rows) { model.PRODUCT.Add(new PRODUCT() { PrdID = rs }); } } if (_PromotionRepository.UpdatePROMOTION(model) == true) { return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { success = false }, JsonRequestBehavior.AllowGet)); } return(RedirectToAction("Login2", "Account")); } return(View()); } else { return(RedirectToAction("Login2", "Account")); } }
public frmChinhSuaKhuyenMai(frmKhuyenMai _frm, PROMOTION makhuyenmai) { InitializeComponent(); InitLookUp_LoaiBang(); ReadXml_User(); gridView1.Invalidate(); gridView1.IndicatorWidth = 40; dateBatDau.DateTime = DateTime.Now; dateHetHan.DateTime = DateTime.Now; dtCreateDate.DateTime = DateTime.Now; objkhuyenmai = makhuyenmai; txtMaKM.Text = makhuyenmai.ID; txtTenKM.Text = makhuyenmai.Name_Promotion; objkhuyenmai = makhuyenmai; frmkhuyenmai = _frm; dtable.Columns.Add("ProductGroup_ID"); dtable.Columns.Add("Discount"); dtable.Columns.Add("DateFrom"); dtable.Columns.Add("DateTo"); gridControl1.DataSource = new PROMOTION_DETAILController().PROMOTION_DETAIL_Get(makhuyenmai.ID); }
public int PROMOTION_Update(PROMOTION obj) { try { return(DataProvider.ExecuteNonquery(DataProvider.ConnectionString, "PROMOTION_Update", obj.ID , obj.Name_Promotion , obj.Refdate , obj.RefType , obj.StartDate , obj.StopDate , obj.CreateBy , obj.Createdate , obj.ModifyBy , obj.ModifyDate , obj.Active)); } catch (Exception ex) { throw ex; } }
public ActionResult PromotionInfo(PROMOTION data) { if (Session["login"] is null) { return(RedirectToAction("Login")); } int idRole = ((USER)Session["login"]).IdRole; if (idRole != 1) { return(RedirectToAction("Index")); } try { if (String.IsNullOrEmpty(data.PromotionName)) { throw new Exception("Tên chương trình khuyến mãi không được bỏ trống"); } if (data.PromotionEnd is null || data.PromotionStart is null) { throw new Exception("Thời gian khuyến mãi không được bỏ trống"); } if (data.PromotionEnd.Value < data.PromotionStart.Value) { throw new Exception("Thời gian khuyến mãi không hợp lệ"); } using (THUONGMAIDIENTUEntities db = new THUONGMAIDIENTUEntities()) { if (data.IdPromotion == 0) { db.PROMOTIONs.Add(data); } else { var promotionDB = db.PROMOTIONs.Where(x => x.IdPromotion == data.IdPromotion).FirstOrDefault(); if (promotionDB is null) { throw new Exception("Không tìm thấy chương trình khuyến mãi này, vui lòng thử lại"); } promotionDB.PromotionName = data.PromotionName; promotionDB.PromotionStart = data.PromotionStart; promotionDB.PromotionEnd = data.PromotionEnd; promotionDB.PRODUCT_PROMOTION.Clear(); if (data.PRODUCT_PROMOTION != null) { foreach (var item in data.PRODUCT_PROMOTION.ToList()) { promotionDB.PRODUCT_PROMOTION.Add(item); } } data = promotionDB; } db.SaveChanges(); } ViewBag.Success = "Chương trình khuyến mãi lưu thành công"; ViewBag.Id = data.IdPromotion; } catch (Exception ex) { ViewBag.Error = ex.Message; } return(View(data)); }