//將excel的資料寫入資料庫 private string InsertGoods(DataTable dt) { string result = ""; BLL.quan bll = new BLL.quan(); Model.quan model = null; //判斷列名是否規範 string[] strColumn = { "名稱", "券號", "金額", "數量", "開始時間", "結束時間", "適用商品" }; int num = 0; for (int i = 0; i < dt.Columns.Count; i++) { foreach (string str in strColumn) { if (str == dt.Columns[i].ColumnName) { num++; } } } if (num == strColumn.Length) { //遍歷主件 foreach (DataRow dr in dt.Rows) { if (dr[0].ToString().Trim() != "" && dr[1].ToString().Trim() != "" && dr[2].ToString().Trim() != "" && dr[3].ToString().Trim() != "") { bool updatea = true; try { model = bll.GetModel(dr[1].ToString()); } catch (Exception eee) { } if (model == null) { model = new Model.quan(); updatea = false; } model.quan_code = dr[1].ToString(); model.quan_title = dr[0].ToString(); model.quan_name = dr[0].ToString(); model.quan_num = Utils.StrToDecimal(dr[2].ToString(), 0); model.quan_sort = Utils.StrToInt(dr[3].ToString(), 0); model.quan_add_date = System.DateTime.Now; model.quan_begin_date = Utils.StrToDateTime(dr[4].ToString()); model.quan_end_date = Utils.StrToDateTime(dr[5].ToString()); model.quan_des = getcode(dr[6].ToString()); model.quan_where = "lin"; int pid = 0; if (updatea) { bll.Update(model); } else { pid = bll.Add(model); } } } } else { result = "請檢查excel檔案格式!" + num + strColumn.Length; } return(result); }
//發送折扣券 protected void btnSubmit_Click(object sender, EventArgs e) { ChkAdminLevelEdit("sys_settings", "Edit"); //ChkAdminLevel("user_sms", TWEnums.ActionEnum.Add.ToString()); //檢查權限 //檢查折扣券內容 if (amount.Text.Trim() == "") { JscriptMsg("請輸入金額!", ""); return; } if (txtEndTime.Text.Trim() == "") { JscriptMsg("請輸入到期時間!", ""); return; } //開始發送折扣券 string msg = string.Empty; bool result = false; Tea.Model.quan model = null; bool update = true; if (id > 0) { model = bll_quan.GetModel(id); } if (model == null) { model = new Model.quan(); update = false; } model.quan_title = txtTitle.Text; model.quan_add_date = System.DateTime.Now; model.quan_begin_date = Utils.StrToDateTime(txtBeginTime.Text, System.DateTime.Now); model.quan_end_date = Utils.StrToDateTime(txtEndTime.Text, System.DateTime.Now); model.quan_where = "lin"; model.quan_num = Utils.StrToDecimal(amount.Text, 0); #region 保存组合商品============== BLL.goods_group bll_good_group = new BLL.goods_group(); StringBuilder idList = new StringBuilder(); string[] goodsGroupIdArr = Request.Form.GetValues("goods_group_id"); string[] parentIdArr = Request.Form.GetValues("parent_id"); string[] goodsIdArr = Request.Form.GetValues("goods_id"); if (goodsGroupIdArr != null && parentIdArr != null && goodsIdArr != null && goodsGroupIdArr.Length > 0 && parentIdArr.Length > 0 && goodsIdArr.Length > 0) { for (int i = 0; i < goodsGroupIdArr.Length; i++) { int groupGoodsId = Utils.StrToInt(goodsGroupIdArr[i], 0); int parentId = Utils.StrToInt(parentIdArr[i], 0); int goodsId = Utils.StrToInt(goodsIdArr[i], 0); idList.Append(goodsId + ","); } } model.quan_des = idList.ToString() + "0"; #endregion model.quan_sort = Utils.StrToInt(txtJin.Text, 0); if (update) { bll_quan.Update(model); } else { model.quan_code = ljd.function.getUUIDString(12); bll_quan.Add(model); } if (result) { AddAdminLog(TWEnums.ActionEnum.Add.ToString(), "折扣券"); //記錄日誌 JscriptMsg("設定優惠券", "lin_list.aspx"); return; } else { JscriptMsg("設定優惠券", "lin_list.aspx"); return; } }