using System; using System.Collections; 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.Collections.Generic; using System.Text.RegularExpressions; using System.Text; using JsonHelper; using DSWeb.Models; using DSWeb.EntityDA; using DSWeb.Log; using DSWeb.Authority; namespace DSWeb.ParameterSet { public partial class CrmKeyCodeSet : PageBase { private string recvJSON; private string strUserID; private string strCompanyID;//公司GID private string strShowName;//用户显示名 private string strDeptName;//部门名称 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 (!IsPostBack) { getddlKEYTYPE(); } recvJSON = ""; recvJSON = this.recvContainer.Value.Trim(); if (this.h_post.Value.Trim() != "") { //保存操作 if (this.h_post.Value.Trim() == "1") { if (!recvJSON.Trim().Equals("")) { SaveFeeAction(); } } } } protected void getddlKEYTYPE() { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet ds = T_ALL_DA.GetAllSQL("select KEYTYPE from crm_key_code group by KEYTYPE"); ddlKEYTYPE.Items.Clear(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ddlKEYTYPE.Items.Add(new ListItem(ds.Tables[0].Rows[i]["KEYTYPE"].ToString().Trim(), ds.Tables[0].Rows[i]["KEYTYPE"].ToString().Trim())); } } protected String getBSNO() { string strBSNO = Guid.NewGuid().ToString(); strBSNO = strBSNO.Replace("-", ""); strBSNO = "Key" + strBSNO; return strBSNO; } private void SaveFeeAction() { CrmKeyCodeSetDA CrmKeyCodeSetDA = new EntityDA.CrmKeyCodeSetDA(); IList KeyEntities = new List(); if (!recvJSON.Trim().Equals("")) { KeyEntities = ResolveFeeJSON(recvJSON.Trim(), KeyEntities); recvContainer.Value = ""; // int iResult = CrmKeyCodeSetDA.UpdateAll(KeyEntities); if (iResult > 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", ""); return; } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", ""); return; } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", ""); return; } } private IList ResolveFeeJSON(string tempJSON, IList tempKeyEntities) { 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) { CrmKeyCodeSetEntity model = new CrmKeyCodeSetEntity(); for (int j = 0; j < strCell.Length; j++) { string[] strArg = strCell[j].Split(new char[] { ':' }); switch (strArg[0].Replace("\"", "")) { case "keyid": model.ID = strArg[1].ToString().Replace("\"", "").Trim(); break; case "keytype": model.KEYTYPE = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim()); break; case "keycalue": model.KEYVALUE = UnicodeToGB(strArg[1].ToString().Replace("\"", "").Trim()); break; default: break; } } tempKeyEntities.Add(model); } } } } return tempKeyEntities; } #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 } }