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.Shipping { public partial class CompanysAccount : System.Web.UI.Page { private string recvJSON; private string strSeaBSNO; 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(); if (Request.QueryString["id"] != null) { strSeaBSNO = Request.QueryString["id"].ToString().Trim(); this.dvOrderNumVal.Value = Request.QueryString["id"].ToString().Trim(); if (!recvJSON.Trim().Equals("")) { //应收账户保存 JsonAccountGroupEntity AccountGroupRecvEntity = GetPostEntity(recvJSON); List AccountRecvEntities = new List(); AccountRecvEntities = AccountGroupRecvEntity.JsonAccountEntities; SaveRecvAccount(AccountGroupRecvEntity); //更新完初始化 recvJSON = ""; } } else { Response.Write("-1"); Response.End(); } } #region 保存应收账户列表更改结果 /// /// 保存应收账户列表更改结果 /// /// private void SaveRecvAccount(JsonAccountGroupEntity tempGroupEntity) { if (tempGroupEntity != null) { List AccountEntities = new List(); AccountEntities = tempGroupEntity.JsonAccountEntities; AccountDA AccountDA = new AccountDA(); DataTable AccountTable = new DataTable(); string strInitSql = ""; if (tempGroupEntity.JsonAccountEntities.Count > 0) { string LINKID = tempGroupEntity.JsonAccountEntities[0].Account9.Trim(); strInitSql = " SELECT GID,LINKID,CODENAME,CURRENCY,BANKNAME,ACCOUNT,SubjectCode,FINANCESOFTCODE,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_bank WHERE 1=1 AND LINKID = '" + LINKID + "'"; } else { return; } AccountTable = AccountDA.GetExcuteSql(strInitSql).Tables[0]; //更新操作SQL语句 ArrayList sqlList = new ArrayList(); //日志操作SQL语句 ArrayList logList = new ArrayList(); //日志记录 Logger log = Logger.Instance; for (int i = 0; i < AccountTable.Rows.Count; i++) { foreach (JsonAccountEntity Account in AccountEntities) { if (AccountTable.Rows[i]["GID"].ToString().Trim().Equals(Account.Account1.Trim())) { string strSql = ""; string LogContent = ""; LogEntity logEntity = new LogEntity(); #region 更改前后信息对比 //代码 string strAccountCODENAME = Account.Account2.Trim().ToLower().Equals("null") ? "" : Account.Account2.Trim(); if (!AccountTable.Rows[i]["CODENAME"].ToString().Trim().Equals(strAccountCODENAME)) { strSql += String.Format(" CODENAME = '{0}'", strAccountCODENAME); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "账户代码", AccountTable.Rows[i]["CODENAME"].ToString().Trim(), strAccountCODENAME); } //币别 string strAccountCURRENCY = Account.Account3.Trim().ToLower().Equals("null") ? "" : Account.Account3.Trim(); if (!AccountTable.Rows[i]["CURRENCY"].ToString().Trim().Equals(strAccountCURRENCY)) { strSql += String.Format(",CURRENCY = '{0}'", strAccountCURRENCY); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "账户名称", AccountTable.Rows[i]["CURRENCY"].ToString().Trim(), strAccountCURRENCY); } //银行名称 string strAccountBANKNAME = Account.Account4.Trim().ToLower().Equals("null") ? "" : Account.Account4.Trim(); if (!AccountTable.Rows[i]["BANKNAME"].ToString().Trim().Equals(strAccountBANKNAME)) { strSql += String.Format(",BANKNAME = '{0}'", strAccountBANKNAME); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "账户经理", AccountTable.Rows[i]["BANKNAME"].ToString().Trim(), strAccountBANKNAME); } //银行账户 string strAccountACCOUNT = Account.Account5.Trim().ToLower().Equals("null") ? "" : Account.Account5.Trim(); if (!AccountTable.Rows[i]["ACCOUNT"].ToString().Trim().Equals(strAccountACCOUNT)) { strSql += String.Format(",ACCOUNT = '{0}'", strAccountACCOUNT); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "账户副经理", AccountTable.Rows[i]["ACCOUNT"].ToString().Trim(), strAccountACCOUNT); } //科目代码 string strAccountSubjectCode = Account.Account6.Trim().ToLower().Equals("null") ? "" : Account.Account6.Trim(); if (!AccountTable.Rows[i]["SubjectCode"].ToString().Trim().Equals(strAccountSubjectCode)) { strSql += String.Format(",SubjectCode = '{0}'", strAccountSubjectCode); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "科目代码", AccountTable.Rows[i]["SubjectCode"].ToString().Trim(), strAccountSubjectCode); } //财务软件代码 string strAccountFINANCESOFTCODE = Account.Account7.Trim().ToLower().Equals("null") ? "" : Account.Account7.Trim(); if (!AccountTable.Rows[i]["FINANCESOFTCODE"].ToString().Trim().Equals(strAccountFINANCESOFTCODE)) { strSql += String.Format(",FINANCESOFTCODE = '{0}'", strAccountFINANCESOFTCODE); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "财务软件代码", AccountTable.Rows[i]["FINANCESOFTCODE"].ToString().Trim(), strAccountFINANCESOFTCODE); } //备注 string strAccountREMARK = Account.Account8.Trim().ToLower().Equals("null") ? "" : Account.Account8.Trim(); if (!AccountTable.Rows[i]["REMARK"].ToString().Trim().Equals(strAccountREMARK)) { strSql += String.Format(",REMARK = '{0}'", strAccountREMARK); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "备注", AccountTable.Rows[i]["REMARK"].ToString().Trim(), strAccountREMARK); } //最后一次更新操作人GID string strAccountMODIFIEDUSER = strUserID.Trim().Equals("") ? "" : strUserID.Trim(); if (!AccountTable.Rows[i]["MODIFIEDUSER"].ToString().Trim().Equals(strAccountMODIFIEDUSER)) { strSql += String.Format(",MODIFIEDUSER = '{0}'", strAccountMODIFIEDUSER); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "最后一次更新操作人GID", AccountTable.Rows[i]["MODIFIEDUSER"].ToString().Trim(), strAccountMODIFIEDUSER); } //最后一次更新操作时间 string strAccountMODIFIEDTIME = "GETDATE()"; if (!AccountTable.Rows[i]["MODIFIEDTIME"].ToString().Trim().Equals(strAccountMODIFIEDTIME)) { strSql += String.Format(",MODIFIEDTIME = {0}", strAccountMODIFIEDTIME); LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "最后一次更新操作时间", AccountTable.Rows[i]["MODIFIEDTIME"].ToString().Trim(), strAccountMODIFIEDTIME); } #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}'", "sys_bank", strSql, Account.Account1.Trim()); sqlList.Add(strUpdateSql); logList.Add(String.Format("更新账户标识 {0} {1}", Account.Account1.Trim(), LogContent)); } AccountEntities.Remove(Account); break; } } } if (sqlList.Count > 0) { int iResult = AccountDA.UpdateAccountFromGrid(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 (AccountEntities.Count > 0) { //插入新的应收费用信息 InsertAccount(AccountEntities, 1); } recvJSON = ""; this.recvContainer.Value = ""; } else { recvJSON = ""; this.recvContainer.Value = ""; return; } } #endregion #region 插入账户信息记录 /// /// 插入账户信息记录 /// /// 需要插入账户表的账户实体类 /// 如果iType值为1则记录账户类型为收/否则记录为付 public void InsertAccount(List AccountEntities, int iType) { ArrayList sqlInsertList = new ArrayList(); AccountDA AccountDA = new AccountDA(); foreach (JsonAccountEntity Account in AccountEntities) { string strItemSql = ""; string strValueSql = ""; string strInsertSql = ""; //GID strItemSql += "GID"; strValueSql += String.Format("'{0}'", Account.Account1.Trim().Equals("null") ? "" : Account.Account1.Trim()); //代码 strItemSql += ",CODENAME"; strValueSql += String.Format(",'{0}'", Account.Account2.Trim().Equals("null") ? "" : Account.Account2.Trim()); //币别 strItemSql += ",CURRENCY"; strValueSql += String.Format(",'{0}'", Account.Account3.Trim().Equals("null") ? "" : Account.Account3.Trim()); //银行名称 strItemSql += ",BANKNAME"; strValueSql += String.Format(",'{0}'", Account.Account4.Trim().Equals("null") ? "" : Account.Account4.Trim()); //银行账户 strItemSql += ",ACCOUNT"; strValueSql += String.Format(",'{0}'", Account.Account5.Trim().Equals("null") ? "" : Account.Account5.Trim()); //科目代码 strItemSql += ",SubjectCode"; strValueSql += String.Format(",'{0}'", Account.Account6.Trim().Equals("null") ? "" : Account.Account6.Trim()); //财务软件代码 strItemSql += ",FINANCESOFTCODE"; strValueSql += String.Format(",'{0}'", Account.Account7.Trim().Equals("null") ? "" : Account.Account7.Trim()); //备注 strItemSql += ",REMARK"; strValueSql += String.Format(",'{0}'", Account.Account8.Trim().Equals("null") ? "" : Account.Account8.Trim()); //公司关联id strItemSql += ",LINKID"; strValueSql += String.Format(",'{0}'", Account.Account9); //创建人GID strItemSql += ",CREATEUSER"; strValueSql += String.Format(",'{0}'", strUserID.Trim()); //最后一次更新操作人GID strItemSql += ",MODIFIEDUSER"; strValueSql += String.Format(",'{0}'", strUserID.Trim()); // if (!strItemSql.Trim().Equals("") && !strValueSql.Trim().Equals("")) { if (strItemSql.Trim().StartsWith(",")) { strItemSql = strItemSql.Trim().Substring(1); } if (strValueSql.Trim().StartsWith(",")) { strValueSql = strValueSql.Trim().Substring(1); } strInsertSql = String.Format("INSERT INTO {0} ({1}) VALUES({2})", "sys_bank", strItemSql, strValueSql); sqlInsertList.Add(strInsertSql); } } if (sqlInsertList.Count > 0) { int iResult = AccountDA.InsertAccountFromGrid(sqlInsertList); //为1表示更新成功 //为-1有异常,更新失败 //为-2更新异常,事务已回滚成功 //更新完成后,记录日志 //if (iResult == 1) //{ //} } } #endregion #region 获取账户客户保存的账户信息 /// /// 获取账户客户保存的账户信息 /// /// /// public JsonAccountGroupEntity GetPostEntity(string tempValue) { JsonAccountGroupEntity AccountGroupEntity = (JsonAccountGroupEntity)JSON.Instance.ToObject(tempValue); return AccountGroupEntity; } #endregion } }