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 DSWeb.Models; using DSWeb.EntityDA; using System.Text; namespace DSWeb.Shipping { public partial class CrmOrderFeeGridSource : System.Web.UI.Page { private int iType;//费用类型 应收类型值1 应付类型值 2 private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有费用信息;"add"-添加新的费用信息;"delete"-删除费用信息;"exist"查看是否有与委托相关费用 private int iShowCount;//每页显示数据量 private string strBSNO;//委托编号 private string strHandle; private string strUserID;//用户GID private string strShowName;//用户登录名 private string strCompanyID;//分公司GID private string strDeptName;//部门名称 protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString().Trim(); } if (Session["COMPANYID"] != null) { strCompanyID = Session["COMPANYID"].ToString(); } if (Session["DEPTNAME"] != null) { strDeptName = Session["DEPTNAME"].ToString(); } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } #region 判断参数是否正确 if (Request.QueryString["type"] != null) { iType = int.Parse(Request.QueryString["type"].ToString().Trim()); } if (Request.QueryString["read"] != null) { strReadXmlType = Request.QueryString["read"].ToString().Trim(); } if (Request.QueryString["showcount"] != null) { iShowCount = int.Parse(Request.QueryString["showcount"].ToString()); } if (Request.QueryString["bsno"] != null) { strBSNO = Request.QueryString["bsno"].ToString(); } if (Request.QueryString["handle"] != null) { strHandle = Request.QueryString["handle"].ToString().Trim().ToLower(); } #endregion if (strHandle != null && strBSNO != null) { if (strHandle.Equals("getauditstatus")) { Response.Write(GetAuditStatus(strBSNO)); } if (strHandle.Equals("postaudit")) { Response.Write(PostCrmOrderAudit(strBSNO)); } } else { if (iType > 0 && !strReadXmlType.Equals("")) { string strOutputXml = ""; strOutputXml = GetCells(iShowCount, iType, strReadXmlType); //输出XML字符串 Response.ContentType = "text/xml"; strOutputXml.Replace("&", "&"); Response.Write(strOutputXml); } else { //访问参数不正确 Response.ContentType = "text/xml"; Response.Write("-2"); } } } #region 获取订舱费用审核状态,如果审核状态是 9-录入状态,1-提交审核,0-审核通过,2-审核驳回 /// /// 获取订舱费用审核状态,如果审核状态是 /// /// 9-录入状态,1-提交审核,0-审核通过,2-审核驳回,-1获取数据错误 private string GetAuditStatus(string tempORDNO) { string strStatus = ""; CrmSeaeorderDA crmSeaeOrderDA = new CrmSeaeorderDA(); CrmSeaeorderEntity crmSeaeOrderEntity = new CrmSeaeorderEntity(); crmSeaeOrderEntity = crmSeaeOrderDA.GetID(tempORDNO); if (crmSeaeOrderEntity != null) { if (crmSeaeOrderEntity.ORDNO != null) { strStatus = crmSeaeOrderEntity.ORSTATUS.ToString(); } else { strStatus = "-1";//获取数据错误 } } else { strStatus = "-1";//获取数据错误 } return strStatus; } #endregion /// /// 获取费用信息 /// /// private string GetCells(int iShowCount, int Type, string readXmlType) { CrmOrderFeeEntity crmOrderFeeEntity = new CrmOrderFeeEntity(); CrmOrderFeeDA crmOrderFeeDA = new CrmOrderFeeDA(); CrmOrderFeeEntity existCrmOrderFeeEntity = new CrmOrderFeeEntity(); existCrmOrderFeeEntity = crmOrderFeeDA.GetCrmOrderFeeByBSNOAndType(strBSNO, Type); if (existCrmOrderFeeEntity != null && !strReadXmlType.Equals("exist")) { //获取所有费用信息,用做Grid显示 DataTable feeTable = new DataTable(); //初始化 string strInitSql = " SELECT {0} GID, FEESTATUS, FEENAME, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY,COMMISSIONRATE,AMOUNT, CURRENCY, " + " EXCHANGERATE,FEEFRT,REMARK,ISADVANCEDPAY FROM crm_orderfee WHERE 1> 0 {1} {2} {3}"; string strSql = ""; if (iType == 1) { if (iShowCount > 0) { //strSql = string.Format(strInitSql, "top " + iShowCount, " AND FEETYPE like '%收%' ", " ORDER BY ENTERDATE DESC "); strSql = string.Format(strInitSql, "", " AND FEETYPE = 1 ", "AND BSNO = '" + strBSNO + "'", " ORDER BY ENTERDATE ASC "); } else { strSql = string.Format(strInitSql, "", " AND FEETYPE = 1 ", "AND BSNO = '" + strBSNO + "'", " ORDER BY ENTERDATE ASC "); } } else { if (iShowCount > 0) { //strSql = string.Format(strInitSql, "top " + iShowCount, " AND FEETYPE like '%付%' ", " ORDER BY ENTERDATE DESC "); strSql = string.Format(strInitSql, "", " AND FEETYPE = 2 ", "AND BSNO = '" + strBSNO + "'", " ORDER BY ENTERDATE ASC "); } else { strSql = string.Format(strInitSql, "", " AND FEETYPE = 2 ", "AND BSNO = '" + strBSNO + "'", " ORDER BY ENTERDATE ASC "); } } feeTable = getStatusNameTable(crmOrderFeeDA.GetFeeListByCondition(strSql).Tables[0]); //编排字符串 xml串 StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); int iCount = feeTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = feeTable.Columns.Count; dataBuilder.Append(""); dataBuilder.Append("0"); for (int j = 1; j < jCount; j++) { switch (j) { case 2://FEENAME dataBuilder.Append(GetFeeCodeCells(feeTable.Rows[i][j].ToString().Trim())); break; case 3://CUSTOMERNAME dataBuilder.Append(GetCRMClientCells(feeTable.Rows[i][j].ToString().Trim())); break; case 4: dataBuilder.Append(GetUnitCells(feeTable.Rows[i][j].ToString().Trim())); break; case 9: dataBuilder.Append(GetCurrencyCells(feeTable.Rows[i][j].ToString().Trim())); break; case 10: dataBuilder.Append("" + feeTable.Rows[i][j].ToString() + ""); break; case 11: dataBuilder.Append(GetFRTCells(feeTable.Rows[i][j].ToString())); break; case 13: string strIsAdvancedPay = feeTable.Rows[i][j].ToString().Trim().ToLower(); if (strIsAdvancedPay.Equals("true")) { dataBuilder.Append("1"); } else { dataBuilder.Append("0"); } break; default: dataBuilder.Append("" + feeTable.Rows[i][j].ToString() + ""); break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else if (existCrmOrderFeeEntity != null && strReadXmlType.Equals("exist")) { return "1";//存在费用 } else if (existCrmOrderFeeEntity == null && strReadXmlType.Equals("add")) { StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append("录入状态"); dataBuilder.Append(GetFeeCodeCells("")); dataBuilder.Append(GetCRMClientCells("")); dataBuilder.Append(GetUnitCells("")); dataBuilder.Append("0"); dataBuilder.Append("0"); dataBuilder.Append("0"); dataBuilder.Append("0"); dataBuilder.Append(GetCurrencyCells("RMB")); dataBuilder.Append("0"); dataBuilder.Append(GetFRTCells("PP")); dataBuilder.Append(""); dataBuilder.Append("0"); dataBuilder.Append(""); dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的费用 } } #region 获取CRM系统客户信息下拉列表 /// /// 获取CRM系统客户信息下拉列表 /// /// 当前列表客户信息值 /// public string GetCRMClientCells(string strClientValue) { CRMClientDA crmClientDA = new CRMClientDA(); //DataTable clientTable = crmClientDA.GetCRMClientList().Tables[0]; StringBuilder clientBuilder = new StringBuilder(); clientBuilder.Append("" + strClientValue); //for (int i = 0; i < clientTable.Rows.Count; i++) //{ // if (!clientTable.Rows[i]["SHORTNAME"].ToString().Trim().Equals("")) // { // clientBuilder.Append(""); // } //} clientBuilder.Append(""); return clientBuilder.ToString(); } #endregion #region 获取币别信息下拉列表 /// /// 获取币别信息下拉列表 /// /// public string GetCurrencyCells(string strCurrencyValue) { CurrencyDA currencyDA = new CurrencyDA(); //DataTable currencyTable = currencyDA.GetCurrencyList().Tables[0]; StringBuilder currencyBuilder = new StringBuilder(); currencyBuilder.Append("" + strCurrencyValue); //for (int i = 0; i < currencyTable.Rows.Count; i++) //{ // if (!currencyTable.Rows[i]["DESCRIPTION"].ToString().Trim().Equals("")) // { // currencyBuilder.Append(""); // } //} currencyBuilder.Append(""); return currencyBuilder.ToString(); } #endregion #region 获取费用代码信息下拉列表 /// /// 获取费用代码信息下拉列表 /// /// /// public string GetFeeCodeCells(string strFeeCodeValue) { FeeCodeDA feeCodeDA = new FeeCodeDA(); //DataTable feeCodeTable = feeCodeDA.GetFeeCodeList().Tables[0]; StringBuilder feeCodeBuilder = new StringBuilder(); feeCodeBuilder.Append("" + strFeeCodeValue); //for (int i = 0; i < feeCodeTable.Rows.Count; i++) //{ // if (!feeCodeTable.Rows[i]["NAME"].ToString().Trim().Equals("")) // { // feeCodeBuilder.Append(""); // } //} feeCodeBuilder.Append(""); return feeCodeBuilder.ToString(); } #endregion #region 获取标准信息下拉列表 /// /// 获取标准信息下拉列表 /// /// /// public string GetUnitCells(string strUnitValue) { StringBuilder unitBuilder = new StringBuilder(); unitBuilder.Append("" + strUnitValue); unitBuilder.Append(""); unitBuilder.Append(""); //unitBuilder.Append(""); unitBuilder.Append(""); unitBuilder.Append(""); unitBuilder.Append(""); unitBuilder.Append(""); unitBuilder.Append(""); unitBuilder.Append(""); return unitBuilder.ToString(); } #endregion #region 获取引入类型信息下拉列表 /// /// 获取引入类型信息下拉列表 /// /// /// public string GetFRTCells(string strFRTValue) { StringBuilder frtBuilder = new StringBuilder(); frtBuilder.Append("" + strFRTValue); frtBuilder.Append(""); frtBuilder.Append(""); frtBuilder.Append(""); return frtBuilder.ToString(); } #endregion /// /// 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字 /// /// 原数据源DataTable /// 返回新数据源DataTable private DataTable getStatusNameTable(DataTable tempTable) { DataTable sourceTable = tempTable; DataTable cloneTable = new DataTable(); int iSwitch = 0; for (int i = 0; i < sourceTable.Rows.Count; i++) { if (iSwitch == 0) { for (int j = 0; j < sourceTable.Columns.Count; j++) { if (sourceTable.Columns[j].ColumnName.Equals("FEESTATUS")) { DataColumn newColumn = new DataColumn(); newColumn.ColumnName = sourceTable.Columns[j].ColumnName; newColumn.DataType = System.Type.GetType("System.String"); cloneTable.Columns.Add(newColumn); } else { DataColumn newColumn = new DataColumn(); newColumn.ColumnName = sourceTable.Columns[j].ColumnName; newColumn.DataType = sourceTable.Columns[j].DataType; cloneTable.Columns.Add(newColumn); } } iSwitch = 1; } DataRow cloneRow = cloneTable.NewRow(); for (int k = 0; k < sourceTable.Columns.Count; k++) { if (sourceTable.Columns[k].ColumnName.Equals("FEESTATUS")) { int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString()); string strFeeStatus = ""; switch (iFeeStatus) { case 0: strFeeStatus = "审核通过"; break; case 1: strFeeStatus = "录入状态"; break; case 2: strFeeStatus = "提交审核"; break; case 3: strFeeStatus = "申请修改"; break; case 4: strFeeStatus = "申请删除"; break; case 5: strFeeStatus = "取消申请"; break; case 6: strFeeStatus = "驳回提交"; break; case 7: strFeeStatus = "驳回申请"; break; case 8: strFeeStatus = "部分结算"; break; case 9: strFeeStatus = "结算完毕"; break; case 10: strFeeStatus = "申请通过"; break; default: break; } cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus; } else { cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k]; } } cloneTable.Rows.Add(cloneRow); } //cloneTable.Columns.Remove("FEESTATUS"); //cloneTable.Columns.Add(new DataColumn("FEESTATUS", System.Type.GetType("System.String"))); return cloneTable; } #region 销售订舱提交审核 /// /// 销售订舱提交审核 /// /// 销售订舱业务编号 /// 值1表示提交审核成功 值不等 表示提交审核失败 private int PostCrmOrderAudit(string tempBSNO) { int iResult = 0; CrmSeaeorderDA crmSeaeOrderDA = new CrmSeaeorderDA(); if (crmSeaeOrderDA.GetCrmOrderFeeCountByOrderNO(tempBSNO) > 0) { iResult = crmSeaeOrderDA.PostAudit(tempBSNO, "1", ""); if (iResult == 1) { IList userAuthorityRangeEntities = new List(); UserAuthorityDA userAuthorityDA = new UserAuthorityDA(); userAuthorityRangeEntities = userAuthorityDA.GetAuthorityUsersByNameAndRange("modSeaeOrderAudit", 2); IList messageEntities = new List(); MessageDA messageDA = new MessageDA(); if (userAuthorityRangeEntities.Count > 0) { foreach (UserAuthorityRangeEntity userAuthorityRangeEntity in userAuthorityRangeEntities) { UserDA userDA = new UserDA(); CompanyDA companyDA = new CompanyDA(); CompanyEntity companyEntity = new CompanyEntity(); //先获取提交销售订舱申请人的分公司、部门信息 string applyCompanyID = strCompanyID; string applyDeptName = userDA.GetUserDepartmentName(strUserID); //再获取具有销售订舱审核权限的审核人分公司、部门信息 companyEntity = companyDA.GetCompanyByUserID(userAuthorityRangeEntity.UserID); if (companyEntity != null) { if (companyEntity.GID != null) { string auditorCompanyID = companyEntity.GID; string auditorDeptName = userDA.GetUserDepartmentName(userAuthorityRangeEntity.UserID); if (applyCompanyID == auditorCompanyID) { //相同分公司下 if (applyDeptName == auditorDeptName) { //插入消息提醒 MessageEntity messageEntity = new MessageEntity(); messageEntity.GID = Guid.NewGuid().ToString(); messageEntity.Name = "SeaOrderAudit"; messageEntity.Description = "销售订舱待审核通知"; messageEntity.IsRead = false; messageEntity.ReadCount = 0; messageEntity.MessageContent = strShowName + " 提交 [销售订舱审核] 申请,请审核 "; messageEntity.TaskID = ""; messageEntity.Receiver = userAuthorityRangeEntity.UserID; messageEntity.TaskUrl = "shipping/SeaeOrderAudit.aspx"; messageEntity.Type = messageDA.GetMessageType(MessageType.SEAORDERAUDIT); messageEntity.RecvType = 2;//申请审核类型 messageEntities.Add(messageEntity); } } } } } } if (messageEntities.Count > 0) { messageDA.CreateMessage(MessageType.SEAORDERAUDIT, messageEntities); } } } else { iResult = -3;//销售订舱未录费用不能提交审核 } return iResult; } #endregion } }