You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/SeaiInfo/ImportReceiptList.aspx.cs

455 lines
24 KiB
C#

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.SeaiInfo
{
public partial class ImportReceiptList : System.Web.UI.Page
{
private string recvJSON;
public string strBSNO;
RangeDA RangeDA = new RangeDA();
public string strUserID;//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
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 = "";
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
recvJSON = "";
recvJSON = this.recvContainer.Value.Trim();
if (Request.QueryString["id"] != null)
{
strBSNO = Request.QueryString["id"].ToString().Trim();
this.dvOrderNumVal.Value = Request.QueryString["id"].ToString().Trim();
//权限可视范围
this.hdRangeV.Value = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modSeaImportList");
this.hdRangeO.Value = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modSeaImportList");
//页面是否只读
if (Request.QueryString["hdenabled"] != null)
{
if (Request.QueryString["hdenabled"].ToString() == "false")
{
this.hdRangeO.Value = "4";
}
}
//
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.GetSeaImportListCompany(strUserID.Trim(), strBSNO);
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.GetSeaImportListDEPT(strUserID.Trim(), strBSNO);
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.GetSeaImportListPerson(strUserID.Trim(), strBSNO);
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 (!recvJSON.Trim().Equals(""))
{
//应收账户保存
JsonImportReceiptListGroupEntity ImportReceiptListGroupRecvEntity = GetPostEntity(recvJSON);
List<JsonImportReceiptListEntity> ImportReceiptListRecvEntities = new List<JsonImportReceiptListEntity>();
ImportReceiptListRecvEntities = ImportReceiptListGroupRecvEntity.JsonImportReceiptListEntities;
SaveRecvImportReceiptList(ImportReceiptListGroupRecvEntity);
//更新完初始化
recvJSON = "";
}
}
else
{
Response.Write("-1");
Response.End();
}
}
#region 保存应收账户列表更改结果
/// <summary>
/// 保存应收账户列表更改结果
/// </summary>
/// <param name="tempGroupEntity"></param>
private void SaveRecvImportReceiptList(JsonImportReceiptListGroupEntity tempGroupEntity)
{
if (tempGroupEntity != null)
{
List<JsonImportReceiptListEntity> ImportReceiptListEntities = new List<JsonImportReceiptListEntity>();
ImportReceiptListEntities = tempGroupEntity.JsonImportReceiptListEntities;
ImportReceiptListDA ImportReceiptListDA = new ImportReceiptListDA();
DataTable DTable = new DataTable();
string strInitSql = "";
if (tempGroupEntity.JsonImportReceiptListEntities.Count > 0)
{
strInitSql = "SELECT [Id],RECEIPTTYPE,Receiptno,RECEIPTSTATE,Send_date,Receive_date,Trancer,TrancNo,remark,MODIFIEDUSER=(SELECT top 1 SHOWNAME from [user] where GID=Import_receipt.MODIFIEDUSER),MODIFIEDTIME FROM Import_receipt WHERE BSNO = '" + strBSNO + "' ORDER BY [Id] ASC";
}
else
{
return;
}
DTable = ImportReceiptListDA.GetExcuteSql(strInitSql).Tables[0];
//更新操作SQL语句
ArrayList sqlList = new ArrayList();
//日志操作SQL语句
ArrayList logList = new ArrayList();
//日志记录
Logger log = Logger.Instance;
for (int i = 0; i < DTable.Rows.Count; i++)
{
foreach (JsonImportReceiptListEntity ImportReceiptList in ImportReceiptListEntities)
{
if (DTable.Rows[i]["Id"].ToString().Trim().Equals(ImportReceiptList.ImportReceiptList1.ToString().Trim()))//惟一编号
{
string strSql = "";
string LogContent = "";
LogEntity logEntity = new LogEntity();
#region 更改前后信息对比
//单据类型
string strRECEIPTTYPE = ImportReceiptList.ImportReceiptList2.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList2.Trim();
if (!DTable.Rows[i]["RECEIPTTYPE"].ToString().Trim().Equals(strRECEIPTTYPE))
{
strSql += String.Format(" RECEIPTTYPE = '{0}'", strRECEIPTTYPE);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "单据类型", DTable.Rows[i]["RECEIPTTYPE"].ToString().Trim(), strRECEIPTTYPE);
}
//单据编号
string strReceiptno = ImportReceiptList.ImportReceiptList3.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList3.Trim();
if (!DTable.Rows[i]["Receiptno"].ToString().Trim().Equals(strReceiptno))
{
strSql += String.Format(" Receiptno = '{0}'", strReceiptno);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "单据编号", DTable.Rows[i]["Receiptno"].ToString().Trim(), strReceiptno);
}
//单据状态
string strRECEIPTSTATE = ImportReceiptList.ImportReceiptList4.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList4.Trim();
if (!DTable.Rows[i]["RECEIPTSTATE"].ToString().Trim().Equals(strRECEIPTSTATE))
{
strSql += String.Format(" RECEIPTSTATE = '{0}'", strRECEIPTSTATE);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "单据状态", DTable.Rows[i]["RECEIPTSTATE"].ToString().Trim(), strRECEIPTSTATE);
}
//发出时间
string strSend_date = ImportReceiptList.ImportReceiptList5.ToString().Trim().ToLower().Equals("null") ? "null" : ImportReceiptList.ImportReceiptList5.ToString().Trim();
if (!DTable.Rows[i]["Send_date"].ToString().Trim().Equals(strSend_date))
{
if (strSend_date.Trim().Equals("null") || strSend_date.Trim().Equals(""))
{
strSql += String.Format(",Send_date ={0}", strSend_date);
}
else
{
strSql += String.Format(",Send_date = '{0}'", strSend_date);
}
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "发出时间", DTable.Rows[i]["Send_date"].ToString().Trim(), strSend_date);
}
//收到时间
string strReceive_date = ImportReceiptList.ImportReceiptList6.ToString().Trim().ToLower().Equals("null") ? "null" : ImportReceiptList.ImportReceiptList6.ToString().Trim();
if (!DTable.Rows[i]["Receive_date"].ToString().Trim().Equals(strReceive_date))
{
if (strReceive_date.Trim().Equals("null") || strReceive_date.Trim().Equals(""))
{
strSql += String.Format(",Receive_date ={0}", strReceive_date);
}
else
{
strSql += String.Format(",Receive_date = '{0}'", strReceive_date);
}
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "收到时间", DTable.Rows[i]["Receive_date"].ToString().Trim(), strReceive_date);
}
//快递公司
string strTrancer = ImportReceiptList.ImportReceiptList7.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList7.Trim();
if (!DTable.Rows[i]["Trancer"].ToString().Trim().Equals(strTrancer))
{
strSql += String.Format(",Trancer = '{0}'", strTrancer);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "快递公司", DTable.Rows[i]["Trancer"].ToString().Trim(), strTrancer);
}
//快递单号
string strTrancNo = ImportReceiptList.ImportReceiptList8.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList8.Trim();
if (!DTable.Rows[i]["TrancNo"].ToString().Trim().Equals(strTrancNo))
{
strSql += String.Format(",TrancNo = '{0}'", strTrancNo);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "快递单号", DTable.Rows[i]["TrancNo"].ToString().Trim(), strTrancNo);
}
//备注
string strremark = ImportReceiptList.ImportReceiptList9.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList9.Trim();
if (!DTable.Rows[i]["remark"].ToString().Trim().Equals(strremark))
{
strSql += String.Format(",remark = '{0}'", strremark);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "备注", DTable.Rows[i]["remark"].ToString().Trim(), strremark);
}
//录入人
string strMODIFIEDUSER = ImportReceiptList.ImportReceiptList10.Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList10.Trim();
if (!DTable.Rows[i]["MODIFIEDUSER"].ToString().Trim().Equals(strMODIFIEDUSER))
{
strSql += String.Format(",MODIFIEDUSER = '{0}'", strUserID);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "录入人", DTable.Rows[i]["MODIFIEDUSER"].ToString().Trim(), strMODIFIEDUSER);
}
//录入时间
string strMODIFIEDTIME = ImportReceiptList.ImportReceiptList11.ToString().Trim().ToLower().Equals("null") ? "" : ImportReceiptList.ImportReceiptList11.ToString().Trim();
if (!DTable.Rows[i]["MODIFIEDTIME"].ToString().Trim().Equals(strMODIFIEDTIME))
{
strSql += String.Format(",MODIFIEDTIME = '{0}'", strMODIFIEDTIME);
LogContent += String.Format(log.GetLogContentTemplate(Logger.LogTypes.UPDATE), "录入时间", DTable.Rows[i]["MODIFIEDTIME"].ToString().Trim(), strMODIFIEDTIME);
}
#endregion
//如果有字段内容更新则执行更新操作
if (LogContent.Trim().Length > 1)
{
if (strSql.Trim().StartsWith(","))
{
strSql = strSql.Trim().Substring(1);
}
string strUpdateSql = String.Format("UPDATE {0} SET {1} WHERE Id = {2}", "Import_receipt", strSql, ImportReceiptList.ImportReceiptList1.ToString().Trim());
sqlList.Add(strUpdateSql);
logList.Add(String.Format("更新账户标识 {0} {1}", ImportReceiptList.ImportReceiptList1.ToString().Trim(), LogContent));
}
ImportReceiptListEntities.Remove(ImportReceiptList);
break;
}
}
}
if (sqlList.Count > 0)
{
int iResult = ImportReceiptListDA.UpdateFromGrid(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 (ImportReceiptListEntities.Count > 0)
{
//插入新的应收费用信息
InsertImportReceiptList(ImportReceiptListEntities, 1);
}
recvJSON = "";
this.recvContainer.Value = "";
}
else
{
recvJSON = "";
this.recvContainer.Value = "";
return;
}
}
#endregion
#region 插入账户信息记录
/// <summary>
/// 插入账户信息记录
/// </summary>
/// <param name="ImportReceiptListEntities">需要插入账户表的账户实体类</param>
/// <param name="iType">如果iType值为1则记录账户类型为收/否则记录为付</param>
public void InsertImportReceiptList(List<JsonImportReceiptListEntity> ImportReceiptListEntities, int iType)
{
ArrayList sqlInsertList = new ArrayList();
ImportReceiptListDA ImportReceiptListDA = new ImportReceiptListDA();
foreach (JsonImportReceiptListEntity ImportReceiptList in ImportReceiptListEntities)
{
string strItemSql = "";
string strValueSql = "";
string strInsertSql = "";
//ST_ID
//strItemSql += "ST_ID";
//strValueSql += String.Format("'{0}'", ImportReceiptList.ImportReceiptList1.ToString().Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList1.ToString().Trim());
//单据类型
strItemSql += "RECEIPTTYPE";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList2.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList2.Trim());
//单据编号
strItemSql += ",Receiptno";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList3.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList3.Trim());
//单据状态
strItemSql += ",RECEIPTSTATE";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList4.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList4.Trim());
//发出时间
string rq = ImportReceiptList.ImportReceiptList5.ToString().Trim().Equals("null") ? "null" : ImportReceiptList.ImportReceiptList5.ToString().Trim();
if (!rq.Trim().Equals("null") && !rq.Trim().Equals(""))
{
strItemSql += ",Send_date";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList5.ToString().Trim());
}
//收到时间
rq = ImportReceiptList.ImportReceiptList6.ToString().Trim().Equals("null") ? "null" : ImportReceiptList.ImportReceiptList6.ToString().Trim();
if (!rq.Trim().Equals("null") && !rq.Trim().Equals(""))
{
strItemSql += ",Receive_date";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList6.ToString().Trim());
}
//快递公司
strItemSql += ",Trancer";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList7.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList7.Trim());
//快递单号
strItemSql += ",TrancNo";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList8.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList8.Trim());
//备注
strItemSql += ",remark";
strValueSql += String.Format(",'{0}'", ImportReceiptList.ImportReceiptList9.Trim().Equals("null") ? "" : ImportReceiptList.ImportReceiptList9.Trim());
//录入人
strItemSql += ",CREATEUSER";
strValueSql += String.Format(",'{0}'", strUserID.Trim());
//录入时间
strItemSql += ",CREATETIME";
strValueSql += ",getdate()";
//更改操作人gid
strItemSql += ",MODIFIEDUSER";
strValueSql += String.Format(",'{0}'", strUserID.Trim());
//更改操作时间
strItemSql += ",MODIFIEDTIME";
strValueSql += ",getdate()";
//业务编号
strItemSql += ",BSNO";
strValueSql += String.Format(",'{0}'", strBSNO);
//分公司代码
strItemSql += ",CORPID";
strValueSql += String.Format(",'{0}'", strCompanyID);
//分公司代码
strItemSql += ",ContractNo";
strValueSql += String.Format(",'{0}'", strBSNO);
//
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})", "Import_receipt", strItemSql, strValueSql);
sqlInsertList.Add(strInsertSql);
}
}
if (sqlInsertList.Count > 0)
{
int iResult = ImportReceiptListDA.InsertFromGrid(sqlInsertList);
//为1表示更新成功
//为-1有异常,更新失败
//为-2更新异常,事务已回滚成功
//更新完成后,记录日志
//if (iResult == 1)
//{
//}
}
}
#endregion
#region 获取账户客户保存的账户信息
/// <summary>
/// 获取账户客户保存的账户信息
/// </summary>
/// <param name="tempValue"></param>
/// <returns></returns>
public JsonImportReceiptListGroupEntity GetPostEntity(string tempValue)
{
JsonImportReceiptListGroupEntity ImportReceiptListGroupEntity = (JsonImportReceiptListGroupEntity)JSON.Instance.ToObject(tempValue);
return ImportReceiptListGroupEntity;
}
#endregion
}
}