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/Shipping/SeaExportInfoBlissueSurGrid...

407 lines
17 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
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.Text;
using DSWeb.EntityDA;
using DSWeb.Models;
using System.Xml;
using System.Text.RegularExpressions;
namespace DSWeb.Shipping
{
public partial class SeaExportInfoBlissueSurGridSource : System.Web.UI.Page
{
private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户
private int iShowCount;//每页显示数据量
private string strBSNO;//委托编号
//delete
private string strOpBlissueGid;//账户信息GID
private string strHandle;//账户操作说明
private const int iResult = -99;//参数错误
T_ALL_DA T_ALL_DA = new T_ALL_DA();
private string strRange = String.Empty;//权限可视范围
RangeDA RangeDA = new RangeDA();
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;
}
//
#region 判断参数是否正确
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();
}
#endregion
//权限可视范围
strRange = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modOrderManagement");
if (strRange.Trim().Equals("0"))//全部
{
strRange = "";
}
else if (strRange.Trim().Equals("1"))//分公司
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementCompany(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("2"))//部门
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementDEPT(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("3"))//个人
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementPerson(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("4"))//无
{
strRange = " and 1<0";
}
else//空
{
strRange = " and 1<0";
}
//
if (!strReadXmlType.Equals(""))
{
if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover"))
{
strOpBlissueGid = (String)Request.QueryString["gid"] as String;
strHandle = (String)Request.QueryString["read"] as String;
if (strOpBlissueGid == null || strHandle == null)
{
Response.Write(iResult);
}
else
{
string strQuery = DoExcute(strOpBlissueGid, strHandle);
Response.Write(strQuery);
}
}
else if (strReadXmlType.Equals("addrq"))
{
string rq = DateTime.Parse(T_ALL_DA.GetStrSQL("sdate", "select getdate() as sdate")).ToString("yyyy-MM-dd HH:mm:ss");
//if (rq.Trim() != "")
//{
// int irq = rq.IndexOf(" ");
// rq = rq.Substring(0, irq);
// rq = rq.Replace("-", "/");
//}
Response.Write(rq);
return;
}
else if (strReadXmlType.Equals("addname"))
{
string strname = T_ALL_DA.GetStrSQL("SHOWNAME", "select SHOWNAME from [user] where GID='" + strUserID.Trim() + "'");
Response.Write(strname);
return;
}
else
{
string strOutputXml = "";
strOutputXml = GetCells(iShowCount, strReadXmlType);
//输出XML字符串
Response.ContentType = "text/xml";
strOutputXml.Replace("&", "&amp;");
Response.Write(strOutputXml);
}
}
else
{
//访问参数不正确
Response.ContentType = "text/xml";
Response.Write("-2");
}
}
/// <summary>
/// 根据用户提交的
/// </summary>
/// <param name="tempGid">账户GID</param>
/// <param name="tempHandle">操作类型 delete删除单条账户</param>
/// <returns>值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息</returns>
private string DoExcute(string tempGid, string tempHandle)
{
string strVal = "";
OpBlissueDA OpBlissueDA = new OpBlissueDA();
//操作类型为删除
if (tempHandle == "delete")
{
int iResult = 0;
//先判断当前要删除的账户是否存在
if (!tempGid.Trim().Equals(""))
{
OpBlissueEntity OpBlissueEntity = new OpBlissueEntity();
OpBlissueEntity = OpBlissueDA.GetOpBlissueID(tempGid);
if (OpBlissueEntity.ID != null)
{
iResult = OpBlissueDA.DeleteById(OpBlissueEntity.ID);
}
else
{
iResult = -3; //未获取相关账户信息
}
}
strVal = iResult.ToString();
}
if (tempHandle == "recover")
{
if (!tempGid.Trim().Equals(""))
{
OpBlissueEntity OpBlissueEntity = new OpBlissueEntity();
OpBlissueEntity = OpBlissueDA.GetOpBlissueID(tempGid);
if (OpBlissueEntity != null)
{
StringBuilder OpBlissueBuilder = new StringBuilder();
OpBlissueBuilder.Append(OpBlissueEntity.ID + ",");
OpBlissueBuilder.Append(OpBlissueEntity.BLSTATUS + ",");
OpBlissueBuilder.Append(OpBlissueEntity.OPTIME + ",");
OpBlissueBuilder.Append(OpBlissueEntity.OPNAME + ",");
OpBlissueBuilder.Append(OpBlissueEntity.DElFLAG + ",");
OpBlissueBuilder.Append(OpBlissueEntity.ISADD + ",");
OpBlissueBuilder.Append(OpBlissueEntity.REMARK);
strVal = OpBlissueBuilder.ToString();
}
else
{
strVal = "-3";
}
}
else
{
strVal = "-3";
}
}
return strVal;
}
/// <summary>
/// 获取账户信息
/// </summary>
/// <returns></returns>
private string GetCells(int iShowCount, string readXmlType)
{
OpBlissueEntity OpBlissueEntity = new OpBlissueEntity();
OpBlissueDA OpBlissueDA = new OpBlissueDA();
IList<OpBlissueEntity> existOpBlissueEntity = new List<OpBlissueEntity>();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
existOpBlissueEntity = OpBlissueDA.GetOpBlissueByBSNO(strBSNO);
if (existOpBlissueEntity.Count > 0 && !strReadXmlType.Equals("exist"))
{
//获取所有账户信息,用做Grid显示
DataTable OpBlissueTable = new DataTable();
//初始化
string strInitSql = "SELECT id,BLSTATUS,OPTIME,OPNAME,DElFLAG=(case DElFLAG when 'True' then '是' when 'False' then '否' end),ISADD=(case ISADD when 'True' then '是' when 'False' then '否' end),REMARK FROM op_blissue where BSNO='" + strBSNO.Trim() + "' " + strRange + " ORDER BY OPTIME DESC";
DataSet ds = T_ALL_DA.GetAllSQL(strInitSql);
int iCount = 0;
if(ds!=null)
{
if (ds.Tables[0].Rows.Count > 0)
{
OpBlissueTable = getStatusNameTable(ds.Tables[0]);
iCount = OpBlissueTable.Rows.Count;
}
}
//编排字符串 xml串
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
for (int i = 0; i < iCount; i++)
{
int jCount = OpBlissueTable.Columns.Count;
dataBuilder.Append("<row id=\"" + OpBlissueTable.Rows[i]["ID"].ToString() + "\">");
for (int j = 1; j < jCount; j++)
{
switch (j)
{
case 1:
//dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
string xl = GetCodeBsstatus(OpBlissueTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 2:
//string rq = OpBlissueTable.Rows[i][j].ToString();
//if (rq.Trim() != "")
//{
// int irq = rq.IndexOf(" ");
// rq = rq.Substring(0, irq);
// rq = rq.Replace("-", "/");
//}
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
break;
case 3:
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
break;
case 4:
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
break;
case 5:
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
break;
case 6:
dataBuilder.Append("<cell>" + OpBlissueTable.Rows[i][j].ToString() + "</cell>");
break;
}
}
dataBuilder.Append("</row>");
}
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else if (existOpBlissueEntity.Count > 0 && strReadXmlType.Equals("exist"))
{
return "1";//存在账户
}
else if (existOpBlissueEntity.Count == 0 && strReadXmlType.Equals("add"))
{
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
dataBuilder.Append("<row id=\"" + Guid.NewGuid().ToString() + "\">");
string strcb = GetCodeBsstatus("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//
string rq = T_ALL_DA.GetStrSQL("rq", "select rq=getdate()");
//if (rq.Trim() != "")
//{
// int irq = rq.IndexOf(" ");
// rq = rq.Substring(0, irq);
// rq = rq.Replace("-", "/");
//}
rq = DateTime.Parse(rq).ToString("yyyy-MM-dd hh:mm:ss");
dataBuilder.Append("<cell>" + rq + "</cell>");
//
string strname = T_ALL_DA.GetStrSQL("SHOWNAME", "select SHOWNAME from [user] where GID='" + strUserID.Trim() + "'");
dataBuilder.Append("<cell>" + strname + "</cell>");
//
dataBuilder.Append("<cell>否</cell>");
dataBuilder.Append("<cell>是</cell>");
dataBuilder.Append("<cell></cell>");
dataBuilder.Append("</row>");
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else
{
return "-3";//没有相关的账户
}
}
/// <summary>
/// 获取CRM系统客户信息下拉列表
/// </summary>
/// <param name="strClientValue">当前列表客户信息值</param>
/// <returns></returns>
public string GetCodeBsstatus(string strClientValue)
{
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strClientValue);
//clientBuilder.Append("<option value=\"申请电放\">申请电放</option>");
//clientBuilder.Append("<option value=\"批准电放\">批准电放</option>");
//clientBuilder.Append("<option value=\"提单电放\">提单电放</option>");
//clientBuilder.Append("<option value=\"申请提单\">申请提单</option>");
//clientBuilder.Append("<option value=\"提单签收\">提单签收</option>");
//clientBuilder.Append("<option value=\"提单签出\">提单签出</option>");
//clientBuilder.Append("<option value=\"放单申请\">放单申请</option>");
//clientBuilder.Append("<option value=\"批准放单\">批准放单</option>");
//
DataSet ds = T_ALL_DA.GetAllSQL("SELECT BLSTATUS FROM op_blissue where BLSTATUS<>'批准电放' and BLSTATUS<>'申请电放' and BLSTATUS<>'申请提单' and BLSTATUS<>'提单电放' and BLSTATUS<>'提单签收' and BLSTATUS<>'提单签出' and BLSTATUS<>'放单申请' and BLSTATUS<>'批准放单' group by BLSTATUS ORDER BY BLSTATUS");
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i]["BLSTATUS"].ToString().Trim().Equals(""))
{
clientBuilder.Append("<option value=\"" + ds.Tables[0].Rows[i]["BLSTATUS"].ToString() + "\">" + ds.Tables[0].Rows[i]["BLSTATUS"].ToString() + "</option>");
}
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
/// <summary>
/// 将数据集表中账户状态OpBlissueStatus和应收应付类型OpBlissueType的数字状态位转换成文字
/// </summary>
/// <param name="tempTable">原数据源DataTable</param>
/// <returns>返回新数据源DataTable</returns>
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++)
{
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++)
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
cloneTable.Rows.Add(cloneRow);
}
return cloneTable;
}
}
}