using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; 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 DSWeb.Models; using System.Collections.Generic; using JsonHelper; using DSWeb.EntityDA; using DSWeb.Log; namespace DSWeb.ParameterSet { public partial class CodeCurrencySet : System.Web.UI.Page { private string recvJSON; RangeDA RangeDA = new RangeDA(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); public string strUserID;//用户GID protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString().Trim(); } else { Server.Transfer("~/Error/FriendError.aspx"); return; //strUserID = ""; } // recvJSON = ""; recvJSON = this.recvContainer.Value.Trim(); /* //权限可视范围 this.hdRangeV.Value = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modOrderManagement"); this.hdRangeO.Value = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modOrderManagement"); string alt = ""; if (this.hdRangeV.Value.Trim() != this.hdRangeO.Value.Trim()) { if (this.hdRangeO.Value.Trim().Equals("0"))//全部 { } else if (this.hdRangeO.Value.Trim().Equals("1"))//分公司 { alt = RangeDA.GetOrderManagementCompany(strUserID.Trim(), strSeaBSNO); if (alt == "") { divadd.Disabled = true; divsave.Disabled = true; divdel.Disabled = true; divrollback.Disabled = true; mygrid_container_recv.Disabled = true; } } else if (this.hdRangeO.Value.Trim().Equals("2"))//部门 { alt = RangeDA.GetOrderManagementDEPT(strUserID.Trim(), strSeaBSNO); if (alt == "") { divadd.Disabled = true; divsave.Disabled = true; divdel.Disabled = true; divrollback.Disabled = true; mygrid_container_recv.Disabled = true; } } else if (this.hdRangeO.Value.Trim().Equals("3"))//个人 { alt = RangeDA.GetOrderManagementPerson(strUserID.Trim(), strSeaBSNO); if (alt == "") { divadd.Disabled = true; divsave.Disabled = true; divdel.Disabled = true; divrollback.Disabled = true; mygrid_container_recv.Disabled = true; } } else if (this.hdRangeO.Value.Trim().Equals("4"))//无 { divadd.Disabled = true; divsave.Disabled = true; divdel.Disabled = true; divrollback.Disabled = true; mygrid_container_recv.Disabled = true; } } */ // if (!IsPostBack) { } // if (!recvJSON.Trim().Equals("")) { //应收账户保存 JsonCodeCurrencySetGroupEntity CodeCurrencySetGroupRecvEntity = GetPostEntity(recvJSON); List CodeCurrencySetRecvEntities = new List(); CodeCurrencySetRecvEntities = CodeCurrencySetGroupRecvEntity.JsonCodeCurrencySetEntities; SaveRecvCodeCurrencySet(CodeCurrencySetGroupRecvEntity); //更新完初始化 recvJSON = ""; } } #region 保存应收账户列表更改结果 /// /// 保存应收账户列表更改结果 /// /// private void SaveRecvCodeCurrencySet(JsonCodeCurrencySetGroupEntity tempGroupEntity) { if (tempGroupEntity != null) { List CodeCurrencySetEntities = new List(); CodeCurrencySetEntities = tempGroupEntity.JsonCodeCurrencySetEntities; CurrencyDA CurrencyDA = new CurrencyDA(); DataTable CodeCurrencySetTable = new DataTable(); string strInitSql = ""; if (tempGroupEntity.JsonCodeCurrencySetEntities.Count > 0) { strInitSql = " SELECT GID,CODENAME,NAME,DESCRIPTION,DEFAULTRATE,FINANCESOFTCODE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM code_currency order by CODENAME"; } else { return; } CodeCurrencySetTable = CurrencyDA.GetExcuteSql(strInitSql).Tables[0]; //更新操作SQL语句 ArrayList sqlList = new ArrayList(); //日志操作SQL语句 ArrayList logList = new ArrayList(); //日志记录 Logger log = Logger.Instance; for (int i = 0; i < CodeCurrencySetTable.Rows.Count; i++) { foreach (JsonCodeCurrencySetEntity CodeCurrencySet in CodeCurrencySetEntities) { if (CodeCurrencySetTable.Rows[i]["GID"].ToString().Trim().Equals(CodeCurrencySet.CodeCurrencySet1.Trim()))//惟一编号 { string strSql = ""; string LogContent = ""; LogEntity logEntity = new LogEntity(); #region 更改前后信息对比 //币别代码 string strCodeName = CodeCurrencySet.CodeCurrencySet2.Trim().ToLower().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet2.Trim(); if (!CodeCurrencySetTable.Rows[i]["CodeName"].ToString().Trim().Equals(strCodeName)) { strSql += String.Format(" CodeName = '{0}'", strCodeName); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "币别代码", CodeCurrencySetTable.Rows[i]["CodeName"].ToString().Trim(), strCodeName); } //英文名称 string strName = CodeCurrencySet.CodeCurrencySet3.Trim().ToLower().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet3.Trim(); if (!CodeCurrencySetTable.Rows[i]["Name"].ToString().Trim().Equals(strName)) { strSql += String.Format(" Name = '{0}'", strName); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "英文名称", CodeCurrencySetTable.Rows[i]["Name"].ToString().Trim(), strName); } //中文名称 string strDescription = CodeCurrencySet.CodeCurrencySet4.Trim().ToLower().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet4.Trim(); if (!CodeCurrencySetTable.Rows[i]["Description"].ToString().Trim().Equals(strDescription)) { strSql += String.Format(",Description = '{0}'", strDescription); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "中文名称", CodeCurrencySetTable.Rows[i]["Description"].ToString().Trim(), strDescription); } //默认汇率值 string strDefaultRate = CodeCurrencySet.CodeCurrencySet5.ToString().Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet5.ToString().Trim(); if (!CodeCurrencySetTable.Rows[i]["DefaultRate"].ToString().Trim().Equals(strDefaultRate)) { strSql += String.Format(",DefaultRate = '{0}'", Decimal.Parse(strDefaultRate)); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "默认汇率值", CodeCurrencySetTable.Rows[i]["DefaultRate"].ToString().Trim(), strDefaultRate); } //财务软件代码 string strFINANCESOFTCODE = CodeCurrencySet.CodeCurrencySet6.Trim().ToLower().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet6.Trim(); if (!CodeCurrencySetTable.Rows[i]["FINANCESOFTCODE"].ToString().Trim().Equals(strFINANCESOFTCODE)) { strSql += String.Format(",FINANCESOFTCODE = '{0}'", strFINANCESOFTCODE); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "财务软件代码", CodeCurrencySetTable.Rows[i]["FINANCESOFTCODE"].ToString().Trim(), strFINANCESOFTCODE); } //最后一次更改操作人 strSql += String.Format(",MODIFIEDUSER = '{0}'", strUserID); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "最后一次更改操作人", CodeCurrencySetTable.Rows[i]["MODIFIEDUSER"].ToString().Trim(), strUserID); //最后一次更改操作时间 strSql += ",MODIFIEDTIME = getdate()"; LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "最后一次更改操作时间", CodeCurrencySetTable.Rows[i]["MODIFIEDTIME"].ToString().Trim(), DateTime.Now.ToString().Trim()); #endregion //如果有字段内容更新则执行更新操作 if (LogContent.Trim().Length > 1) { if (strSql.Trim().StartsWith(",")) { strSql = strSql.Trim().Substring(1); } string strUpdateSql = String.Format("UPDATE {0} SET {1} WHERE GID = '{2}'", "code_currency", strSql, CodeCurrencySet.CodeCurrencySet1.Trim()); sqlList.Add(strUpdateSql); logList.Add(String.Format("更新账户标识 {0} {1}", CodeCurrencySet.CodeCurrencySet1.Trim(), LogContent)); } CodeCurrencySetEntities.Remove(CodeCurrencySet); break; } } } if (sqlList.Count > 0) { int iResult = CurrencyDA.UpdateCodeCurrencySetFromGrid(sqlList); //为1表示更新成功 //为-1有异常,更新失败 //为-2更新异常,事务已回滚成功 //更新完成后,记录日志 if (iResult == 1) { #region 日志记录操作 // INSERT-"INSERT INTO {0} ({1}) VALUES ({2})" @{0}-所要插入记录的表;{1}记录字段值;{2}-记录新值@ //if (logList.Count > 0) //{ // for (int i = 0; i < logList.Count; i++) // { // LogEntity logEntity = new LogEntity(); // logEntity.GID = Guid.NewGuid().ToString(); // logEntity.Name = "更新账户信息列表"; // logEntity.LogType = "UPDATE 更新操作"; // logEntity.CreateUserID = strUserID.Trim();//测试使用数据,正式发布请删除 // logEntity.LogContent = logList[i].ToString(); // log.WriteLog(logEntity); // } //} #endregion } } //如果遍历完所有币别表数据,没有相对应的币别信息,则将剩余的币别信息插入到币别表中 if (CodeCurrencySetEntities.Count > 0) { //插入新的应收币别信息 InsertCodeCurrencySet(CodeCurrencySetEntities, 1); } recvJSON = ""; this.recvContainer.Value = ""; } else { recvJSON = ""; this.recvContainer.Value = ""; return; } } #endregion #region 插入账户信息记录 /// /// 插入账户信息记录 /// /// 需要插入账户表的账户实体类 /// 如果iType值为1则记录账户类型为收/否则记录为付 public void InsertCodeCurrencySet(List CodeCurrencySetEntities, int iType) { ArrayList sqlInsertList = new ArrayList(); CurrencyDA CurrencyDA = new CurrencyDA(); CurrencyEntity CurrencyEntity = new CurrencyEntity(); CurrencyEntity CurrencyEntityGID = new CurrencyEntity(); string alt = ""; foreach (JsonCodeCurrencySetEntity CodeCurrencySet in CodeCurrencySetEntities) { CurrencyEntity.GID = CodeCurrencySet.CodeCurrencySet1.Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet1.Trim(); CurrencyEntity.CodeName = CodeCurrencySet.CodeCurrencySet2.Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet2.Trim(); CurrencyEntity.Name = CodeCurrencySet.CodeCurrencySet3.Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet3.Trim(); CurrencyEntity.Description = CodeCurrencySet.CodeCurrencySet4.Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet4.Trim(); CurrencyEntity.DefaultRate = Decimal.Parse(CodeCurrencySet.CodeCurrencySet5.ToString("F2").Trim().Equals("null") ? "0" : CodeCurrencySet.CodeCurrencySet5.ToString("F2").Trim()); CurrencyEntity.FINANCESOFTCODE = CodeCurrencySet.CodeCurrencySet6.ToString().Trim().Equals("null") ? "" : CodeCurrencySet.CodeCurrencySet6.Trim(); CurrencyEntity.CreateUserID = strUserID; CurrencyEntity.ModifiedUserID = strUserID; // CurrencyEntityGID = CurrencyDA.GetCurrencyByID(CurrencyEntity.GID); if (CurrencyEntityGID.GID == null) { int iResult = CurrencyDA.Add(CurrencyEntity); //为1表示更新成功 //为-1有异常,更新失败 //为-2更新异常,事务已回滚成功 //更新完成后,记录日志 if (iResult == 1) { } } else { alt += CurrencyEntity.GID + ","; } } // //if (alt != "") //{ // alt=alt.Trim().Substring(0,alt.Trim().Length-1); // Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", ""); //} } #endregion #region 获取账户客户保存的账户信息 /// /// 获取账户客户保存的账户信息 /// /// /// public JsonCodeCurrencySetGroupEntity GetPostEntity(string tempValue) { JsonCodeCurrencySetGroupEntity CodeCurrencySetGroupEntity = (JsonCodeCurrencySetGroupEntity)JSON.Instance.ToObject(tempValue); return CodeCurrencySetGroupEntity; } #endregion } }