void fill() { Song.Entities.RechargeSet mm; if (id != 0) { mm = Business.Do <IRecharge>().RechargeSetSingle(id); cbIsEnable.Checked = mm.Rs_IsEnable; tbPw.Text = mm.Rs_Pw; //有效期 tbStart.Text = mm.Rs_LimitStart.ToString("yyyy-MM-dd"); tbEnd.Text = mm.Rs_LimitEnd.ToString("yyyy-MM-dd"); //主题 tbTheme.Text = mm.Rs_Theme; //数量,面额 tbCount.Text = mm.Rs_Count.ToString(); tbPrice.Text = mm.Rs_Price.ToString(); //简介 tbIntro.Text = mm.Rs_Intro; //充值码长度 tbCodeLength.Text = mm.Rs_CodeLength.ToString(); tbPwLength.Text = mm.Rs_PwLength.ToString(); } else { //如果是新增 mm = new Song.Entities.RechargeSet(); tbPw.Text = getUID(); } }
/// <summary> /// 修改是否禁用的状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void sbEnable_Click(object sender, EventArgs e) { StateButton ub = (StateButton)sender; int index = ((GridViewRow)(ub.Parent.Parent)).RowIndex; int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString()); // Song.Entities.RechargeSet entity = Business.Do <IRecharge>().RechargeSetSingle(id); entity.Rs_IsEnable = !entity.Rs_IsEnable; Business.Do <IRecharge>().RechargeSetSave(entity); BindData(null, null); }
/// <summary> /// 使用该充值码 /// </summary> /// <param name="entity"></param> public void CouponUseCode(RechargeCode entity) { //是否被禁用 Song.Entities.RechargeSet set = Gateway.Default.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>(); if (set == null || set.Rs_IsEnable == false) { throw new Exception("该充值码已经被禁用"); } //是否过期 if (!(DateTime.Now > entity.Rc_LimitStart && DateTime.Now < entity.Rc_LimitEnd.Date.AddDays(1))) { throw new Exception("该充值码已经过期"); } //标注已经使用 entity.Rc_IsUsed = true; entity.Rc_UsedTime = DateTime.Now; //产生流水 CouponAccount ca = new CouponAccount(); ca.Ca_Value = entity.Rc_Price; ca.Ac_ID = entity.Ac_ID; ca.Ca_From = 2; ca.Rc_Code = entity.Rc_Code + "-" + entity.Rc_Pw; ca.Ca_Source = "充值码充值"; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { Business.Do <IAccounts>().CouponAdd(ca); tran.Save <RechargeCode>(entity); RechargeSet setEnity = tran.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>(); if (setEnity != null) { setEnity.Rs_UsedCount++; tran.Save <RechargeSet>(setEnity); } tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEnter_Click(object sender, EventArgs e) { Song.Entities.RechargeSet mm = id != 0 ? Business.Do <IRecharge>().RechargeSetSingle(id) : new Song.Entities.RechargeSet(); //主题 mm.Rs_Theme = tbTheme.Text.Trim(); //数量,面额 int count = 0, price = 0; int.TryParse(tbCount.Text, out count); int.TryParse(tbPrice.Text, out price); mm.Rs_Count = count; mm.Rs_Price = price; //有效期 DateTime start = DateTime.Now, end = DateTime.Now; DateTime.TryParse(tbStart.Text, out start); DateTime.TryParse(tbEnd.Text, out end); mm.Rs_LimitStart = start; mm.Rs_LimitEnd = end; //简介 mm.Rs_Intro = tbIntro.Text.Trim(); //密钥,是否禁用 mm.Rs_Pw = tbPw.Text.Trim(); mm.Rs_IsEnable = cbIsEnable.Checked; //充值码长度 mm.Rs_CodeLength = Convert.ToInt32(tbCodeLength.Text); mm.Rs_PwLength = Convert.ToInt32(tbPwLength.Text); //确定操作 try { if (id == 0) { Song.Entities.Organization org = Business.Do <IOrganization>().OrganCurrent(); mm.Org_ID = org.Org_ID; Business.Do <IRecharge>().RechargeSetAdd(mm); } else { Business.Do <IRecharge>().RechargeSetSave(mm); } Master.AlertCloseAndRefresh("操作成功!"); } catch (Exception ex) { Master.Alert(ex.Message); } }
/// <summary> /// 修改充值码设置项 /// </summary> /// <param name="entity">业务实体</param> public void RechargeSetSave(RechargeSet entity) { using (DbTrans tran = Gateway.Default.BeginTrans()) { try { Song.Entities.RechargeSet rs = tran.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>(); //如果新增了充值码 if (rs.Rs_Count < entity.Rs_Count) { _RechargeCodeBuilds(entity, entity.Rs_Count - rs.Rs_Count); } //如果减少的充值码 if (rs.Rs_Count > entity.Rs_Count) { Song.Entities.RechargeCode[] rcs = tran.From <RechargeCode>().Where(RechargeCode._.Rs_ID == entity.Rs_ID && RechargeCode._.Rc_IsUsed == false).ToArray <RechargeCode>(rs.Rs_Count - entity.Rs_Count); foreach (RechargeCode r in rcs) { tran.Delete <RechargeCode>(r); } } tran.Update <RechargeCode>(new Field[] { RechargeCode._.Rc_Price, RechargeCode._.Rc_LimitStart, RechargeCode._.Rc_LimitEnd }, new object[] { entity.Rs_Price, entity.Rs_LimitStart, entity.Rs_LimitEnd }, RechargeCode._.Rs_ID == entity.Rs_ID && RechargeCode._.Rc_IsUsed == false); tran.Save <RechargeSet>(entity); tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } }
/// <summary> /// 导出Excel格式的充值码信息 /// </summary> /// <param name="path">导出文件的路径(服务器端)</param> /// <param name="orgid">机构id</param> /// <param name="rsid">充值码设置项的id</param> /// <returns></returns> public string RechargeCode4Excel(string path, int orgid, int rsid) { HSSFWorkbook hssfworkbook = new HSSFWorkbook(); //xml配置文件 XmlDocument xmldoc = new XmlDocument(); string confing = WeiSha.Common.App.Get["ExcelInputConfig"].VirtualPath + "充值码.xml"; xmldoc.Load(WeiSha.Common.Server.MapPath(confing)); XmlNodeList nodes = xmldoc.GetElementsByTagName("item"); //创建工作簿对象 Song.Entities.RechargeSet rs = Gateway.Default.From <RechargeSet>().Where(RechargeSet._.Rs_ID == rsid).ToFirst <RechargeSet>(); ISheet sheet = hssfworkbook.CreateSheet(rs.Rs_Theme); //sheet.DefaultColumnWidth = 30; //创建数据行对象 IRow rowHead = sheet.CreateRow(0); for (int i = 0; i < nodes.Count; i++) { rowHead.CreateCell(i).SetCellValue(nodes[i].Attributes["Column"].Value); } //生成数据行 ICellStyle style_size = hssfworkbook.CreateCellStyle(); style_size.WrapText = true; WhereClip wc = RechargeCode._.Org_ID == orgid; if (rsid >= 0) { wc.And(RechargeCode._.Rs_ID == rsid); } RechargeCode[] rcodes = Gateway.Default.From <RechargeCode>().Where(wc).OrderBy(RechargeCode._.Rc_CrtTime.Desc).ToArray <RechargeCode>(); for (int i = 0; i < rcodes.Length; i++) { IRow row = sheet.CreateRow(i + 1); for (int j = 0; j < nodes.Count; j++) { Type type = rcodes[i].GetType(); System.Reflection.PropertyInfo propertyInfo = type.GetProperty(nodes[j].Attributes["Field"].Value); //获取指定名称的属性 object obj = propertyInfo.GetValue(rcodes[i], null); if (obj != null) { string format = nodes[j].Attributes["Format"] != null ? nodes[j].Attributes["Format"].Value : ""; string datatype = nodes[j].Attributes["DataType"] != null ? nodes[j].Attributes["DataType"].Value : ""; string defvalue = nodes[j].Attributes["DefautValue"] != null ? nodes[j].Attributes["DefautValue"].Value : ""; string value = ""; switch (datatype) { case "date": DateTime tm = Convert.ToDateTime(obj); value = tm > DateTime.Now.AddYears(-100) ? tm.ToString(format) : ""; break; default: value = obj.ToString(); break; } if (defvalue.Trim() != "") { foreach (string s in defvalue.Split('|')) { string h = s.Substring(0, s.IndexOf("=")); string f = s.Substring(s.LastIndexOf("=") + 1); if (value.ToLower() == h.ToLower()) { value = f; } } } row.CreateCell(j).SetCellValue(value); } } } FileStream file = new FileStream(path, FileMode.Create); hssfworkbook.Write(file); file.Close(); return(path); }