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 DSWeb.EntityDA;
using System.Text;
namespace DSWeb.Shipping
{
public partial class CompanysSysDeptGridSource : System.Web.UI.Page
{
private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有部门信息;"add"-添加新的部门信息;"delete"-删除部门信息;"exist"查看是否有与委托相关部门
private int iShowCount;//每页显示数据量
private string strLINKID;//委托编号
//delete
private string strSysDeptGid;//部门信息GID
private string strHandle;//部门操作说明
private const int iResult = -99;//参数错误
protected void Page_Load(object sender, EventArgs e)
{
#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["LINKID"] != null)
{
strLINKID = Request.QueryString["LINKID"].ToString();
}
#endregion
//
if (!strReadXmlType.Equals(""))
{
if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover"))
{
strSysDeptGid = (String)Request.QueryString["gid"] as String;
strHandle = (String)Request.QueryString["read"] as String;
if (strSysDeptGid == null || strHandle == null)
{
Response.Write(iResult);
}
else
{
string strQuery = DoExcute(strSysDeptGid, strHandle);
Response.Write(strQuery);
}
}
else
{
string strOutputXml = "";
strOutputXml = GetCells(iShowCount, strReadXmlType);
//输出XML字符串
Response.ContentType = "text/xml";
strOutputXml.Replace("&", "&");
Response.Write(strOutputXml);
}
}
else
{
//访问参数不正确
Response.ContentType = "text/xml";
Response.Write("-2");
}
}
///
/// 根据用户提交的
///
/// 部门GID
/// 操作类型 delete删除单条部门
/// 值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关部门信息
private string DoExcute(string tempGid, string tempHandle)
{
string strVal = "";
SysDeptDA SysDeptDA = new SysDeptDA();
//操作类型为删除
if (tempHandle == "delete")
{
int iResult = 0;
//先判断当前要删除的部门是否存在
if (!tempGid.Trim().Equals(""))
{
SysDeptEntity SysDeptEntity = new SysDeptEntity();
SysDeptEntity = SysDeptDA.GetSysDeptByID(tempGid);
if (SysDeptEntity.GID != null)
{
iResult = SysDeptDA.DeleteSysDeptByGid(SysDeptEntity.GID);
}
else
{
iResult = -3; //未获取相关部门信息
}
}
strVal = iResult.ToString();
}
if (tempHandle == "recover")
{
if (!tempGid.Trim().Equals(""))
{
SysDeptEntity SysDeptEntity = new SysDeptEntity();
SysDeptEntity = SysDeptDA.GetSysDeptByID(tempGid);
if (SysDeptEntity != null)
{
StringBuilder SysDeptBuilder = new StringBuilder();
SysDeptBuilder.Append(SysDeptEntity.GID + ",");
SysDeptBuilder.Append(SysDeptEntity.DEPTNO + ",");
SysDeptBuilder.Append(SysDeptEntity.DEPTNAME + ",");
SysDeptBuilder.Append(SysDeptEntity.MANAGE1 + ",");
SysDeptBuilder.Append(SysDeptEntity.MANAGE2 + ",");
SysDeptBuilder.Append(SysDeptEntity.FINANCESOFTCODE + ",");
SysDeptBuilder.Append(SysDeptEntity.REMARK);
strVal = SysDeptBuilder.ToString();
}
else
{
strVal = "-3";
}
}
else
{
strVal = "-3";
}
}
return strVal;
}
///
/// 获取部门信息
///
///
private string GetCells(int iShowCount, string readXmlType)
{
SysDeptEntity SysDeptEntity = new SysDeptEntity();
SysDeptDA SysDeptDA = new SysDeptDA();
SysDeptEntity existSysDeptEntity = new SysDeptEntity();
existSysDeptEntity = SysDeptDA.GetSysDeptByLINKIDAndType(strLINKID);
if (existSysDeptEntity != null && !strReadXmlType.Equals("exist"))
{
//获取所有部门信息,用做Grid显示
DataTable SysDeptTable = new DataTable();
//初始化
string strInitSql = " SELECT GID,LINKID,DEPTNO,DEPTNAME,MANAGE1,MANAGE2,FINANCESOFTCODE,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME FROM sys_dept WHERE LINKID = '" + strLINKID + "' ORDER BY DEPTNO ASC";
SysDeptTable = getStatusNameTable(SysDeptDA.GetExcuteSql(strInitSql).Tables[0]);
//编排字符串 xml串
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("");
dataBuilder.Append("");
int iCount = SysDeptTable.Rows.Count;
for (int i = 0; i < iCount; i++)
{
int jCount = SysDeptTable.Columns.Count;
dataBuilder.Append("");
for (int j = 1; j < jCount; j++)
{
switch (j)
{
case 2:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
case 3:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
case 4:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
case 5:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
case 6:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
case 7:
dataBuilder.Append("" + SysDeptTable.Rows[i][j].ToString() + " | ");
break;
}
}
dataBuilder.Append("
");
}
dataBuilder.Append("");
return dataBuilder.ToString();
}
else if (existSysDeptEntity != null && strReadXmlType.Equals("exist"))
{
return "1";//存在部门
}
else if (existSysDeptEntity == null && strReadXmlType.Equals("add"))
{
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("");
dataBuilder.Append("");
dataBuilder.Append("");
dataBuilder.Append(" | ");
dataBuilder.Append(" | ");
dataBuilder.Append(" | ");
dataBuilder.Append(" | ");
dataBuilder.Append(" | ");
dataBuilder.Append(" | ");
dataBuilder.Append("
");
dataBuilder.Append("");
return dataBuilder.ToString();
}
else
{
return "-3";//没有相关的部门
}
}
///
/// 将数据集表中部门状态SysDeptStatus和应收应付类型SysDeptType的数字状态位转换成文字
///
/// 原数据源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++)
{
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;
}
}
}