using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Text; using DSWeb.EntityDA; using DSWeb.Models; using System.Xml; using System.Text.RegularExpressions; namespace DSWeb.SeaiFee { public partial class WmsRateEdit : System.Web.UI.Page { private string strUserID; private string strCompanyID;//公司GID private string strShowName;//用户显示名 private string strDeptName;//部门名称 //private string strHandle;// add/ edit //private string strSearch;//仓储费率的客户、合同号、货物名称 //private string strCusjoin;//客户信息 private string ratejson;//要保存的费率信息 private string strSeaBSNO; private string strnewcust; protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } if (Session["COMPANYID"] != null) { strCompanyID = Session["COMPANYID"].ToString(); } if (Session["DEPTNAME"] != null) { strDeptName = Session["DEPTNAME"].ToString(); } //if (Request.QueryString["handle"] != null) //{ // strHandle = Request.QueryString["handle"].ToString(); //} if (Request.QueryString["id"] != null) { strSeaBSNO = Request.QueryString["id"].ToString().Trim(); this.h_bsno.Value = strSeaBSNO; } if (Request.QueryString["cust"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strnewcust = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["cust"].ToString().Trim()))); this.h_cust.Value = strnewcust; } //if (Request.QueryString["search"] != null) //{ // UnicodeEncoding unicode = new UnicodeEncoding(); // strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].ToString()))); // this.h_searchJson.Value = strSearch; //} //if (Request.QueryString["cusjoin"] != null) //{ // UnicodeEncoding unicode = new UnicodeEncoding(); // strCusjoin = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["cusjoin"].ToString()))); //} //if (strHandle == "edit") //{ // SetRateComm();//获取仓储费率的客户、合同号、有效期、货物名称 //} //else if (strHandle == "add" && strCusjoin != "") //{ // SetRateCommCus(strCusjoin);//获取仓储费率的客户信息 //} //保存费率 ratejson = this.RateContainer.Value; if (!ratejson.Equals("") && h_post.Value.Equals("1")) { SaveRateAction(); } } #region 将页面post获取的仓储费率信息保存或更新“仓储费率信息表”wms_rate,并返回操作结果 /// /// 将页面post获取的仓储费率信息保存或更新“仓储费率信息表”wms_rate,并返回操作结果 /// private void SaveRateAction() { IList rateEntities = new List(); if (!ratejson.Trim().Equals("")) { rateEntities = ResolveRateJSON(ratejson.Trim(), rateEntities); this.RateContainer.Value = ""; } WmsRateDA rateDA = new WmsRateDA(); foreach (WmsRateEntity rateentity in rateEntities) { string strwhere = String.Format(" GID='{0}' ", rateentity.GID); int strExists = rateDA.GetRecordCount(strwhere); if (strExists ==1) { bool iRecvState = rateDA.Update(rateentity);//rateDA.Add(rateEntities, feeProfitEntity, strSeaBSNO); } else if(strExists ==0) { bool iRecvState = rateDA.Add(rateentity);//rateDA.Add(rateEntities, feeProfitEntity, strSeaBSNO); } } this.h_post.Value = "";//请求状态清空 } #endregion #region 将页面post获取的仓储费率信息读入到仓储费率实体类wms_rate中 /// /// 将页面post获取的仓储费率信息读入到仓储费率实体类wms_rate中 /// /// /// /// 将页面post获取的仓储费率信息读入到仓储费率实体类wms_rate中 private IList ResolveRateJSON(string tempJSON, IList tempRateEntities) { string strFilter = ""; if (tempJSON.IndexOf("[") >= 0 && tempJSON.IndexOf("]") > 0) { strFilter = tempJSON.Substring(tempJSON.IndexOf("[") + 1, tempJSON.IndexOf("]") - tempJSON.IndexOf("[") - 1); string[] strFees = strFilter.Split(new string[] { "},{" }, System.StringSplitOptions.RemoveEmptyEntries); if (strFees.Length > 0) { for (int i = 0; i < strFees.Length; i++) { strFees[i] = strFees[i].ToString().Replace("{", ""); strFees[i] = strFees[i].ToString().Replace("}", ""); string[] strCell = strFees[i].Split(new char[] { ',' }); if (strCell.Length > 0) { WmsRateEntity RateEntity = new WmsRateEntity(); for (int j = 0; j < strCell.Length; j++) { string[] strArg = strCell[j].Split(new char[] { ':' }); switch (strArg[0].Replace("\"", "")) { case "id": RateEntity.GID = strArg[1].ToString().Replace("\"", ""); break; //case "cusid": // RateEntity.CLIENTGID = strArg[1].ToString().Replace("\"", ""); // break; case "cus": RateEntity.CUSTOMERNAME =UnicodeToGB( strArg[1].ToString().Replace("\"", "")); break; //case "no": // RateEntity.CONTRACTNO =strArg[1].ToString().Replace("\"", "") ; // break; //case "bt": // RateEntity.STARTTIME = DateTime.Parse(strArg[1].ToString().Replace("\"", "")); // break; //case "et": // RateEntity.ENDTIME = DateTime.Parse(strArg[1].ToString().Replace("\"", "")); // break; //case "goods": // RateEntity.GOODSNAME = strArg[1].ToString().Replace("\"", ""); // break; case "fgrade": RateEntity.FEEGRADE = int.Parse(strArg[1].ToString().Replace("\"", "")); break; case "fscale": RateEntity.FEESCALE = int.Parse(strArg[1].ToString().Replace("\"", "")); break; case "fprice": RateEntity.FEEPRICE = decimal.Parse(strArg[1].ToString().Replace("\"", "")); break; case "funit": RateEntity.FEEUNIT = "吨天"; break; case "remark": RateEntity.REMARK = strArg[1].ToString().Replace("\"", ""); break; default: break; } } RateEntity.BSNO = strSeaBSNO; RateEntity.CREATEUSER = this.strShowName; RateEntity.MODIFIEDUSER = this.strShowName; tempRateEntities.Add(RateEntity); } } } } return tempRateEntities; } #endregion #region Unicode-GB Code转换 /// /// Unicode-GB Code转换 /// /// 将Unicode编码字符转换成GB编码字符 /// GB Code字符串 public string UnicodeToGB(string text) { UnicodeEncoding unicode = new UnicodeEncoding(); text = unicode.GetString(unicode.GetBytes(Regex.Unescape(text.Trim()))); return text; } /// /// Unicode-GB Code转换 /// /// 将Unicode编码字符转换成GB编码字符 /// GB Code字符串 public string UnicodeToGB_Old(string text) { MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))"); if (mc != null && mc.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (Match m2 in mc) { string v = m2.Value; if (v.IndexOf("\\") >= 0) { string word = v.Substring(2); byte[] codes = new byte[2]; int code = Convert.ToInt32(word.Substring(0, 2), 16); int code2 = Convert.ToInt32(word.Substring(2), 16); codes[0] = (byte)code2; codes[1] = (byte)code; sb.Append(Encoding.Unicode.GetString(codes)); } else { sb.Append(v); } } return sb.ToString(); } else { return text; } } #endregion } }