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/PriceCarrier/CrmPriceCarrierList.aspx.cs

651 lines
28 KiB
C#

3 years ago
using System;
using System.Collections;
using System.Collections.Generic;
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 System.Xml.Linq;
using DSWeb.EntityDA;
using DSWeb.Models;
using JsonHelper;
using System.Xml;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using DSWeb.Authority;
using System.Data.OleDb;
namespace DSWeb.PriceCarrier
{
public partial class CrmPriceCarrierList : System.Web.UI.Page
{
CrmPriceCarrierDA CrmPriceCarrierDA = new CrmPriceCarrierDA();
RangeDA RangeDA = new RangeDA();
public string strUserID;//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
//grid
private string strColumnVal;
private string strType = "25";//Grid模块号
//gridEnd
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();
this.hdCompanyid.Value = strCompanyID.Trim();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
//权限可视范围
this.hdRangeV.Value = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modCrmPriceCarrierList");
this.hdRangeO.Value = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modCrmPriceCarrierList");
this.hdRange.Value = "";
//if (this.hdRangeV.Value.Trim() != this.hdRangeO.Value.Trim())
//{
this.hdRange.Value = "";
if (this.hdRangeO.Value.Trim().Equals("4"))//无
{
this.imgAdd.Disabled = true;
this.imgEdit.Disabled = true;
this.imgDel.Disabled = true;
this.imgFresh.Disabled = true;
this.divexcel.Disabled = true;
this.anylinkmenu1.Disabled = true;
this.btLOCKFLAG0.Disabled = true;
this.btLOCKFLAG1.Disabled = true;
this.btLOCKFLAG2.Disabled = true;
this.btLOCKFLAG3.Disabled = true;
this.anylinkmenu2.Disabled = true;
this.ibIssue0.Disabled = true;
this.ibIssue1.Disabled = true;
this.ibIssue2.Disabled = true;
this.ibIssue3.Disabled = true;
this.import_file.Disabled = true;
btExcel2.Enabled = false;
this.btERAR.Disabled = true;
}
//}
//grid
if (!IsPostBack)
{
strUserID = strUserID.Trim();
}
if (hid_setting.Value.Trim() != "")
{
strColumnVal = hid_setting.Value.Trim();
SaveColumnSetting(strColumnVal);
hid_setting.Value = "";
}
if (hid_header.Value.Trim() != "")
{
strColumnVal = hid_header.Value.Trim();
SaveColumnSetting(strColumnVal);
hid_header.Value = "";
}
//gridEnd
}
protected void btDel_Click(object sender, EventArgs e)
{
string alt = "";
if (this.hid_id.Value.Trim() != "")
{
string[] sDel = this.hid_id.Value.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < sDel.Length; i++)
{
alt += " or GID='" + sDel[i].ToString().Trim() + "'";
}
//
alt = CrmPriceCarrierDA.GetCrmPriceCarrierDel(alt.Trim(), strUserID.Trim());//, "FCL"
if (alt != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key8", "<script>alert('" + alt + "');</script>");
return;
}
else
{
return;
}
}
}
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "EBPQ" + strBSNO;
return strBSNO;
}
protected void btExcel1_Click(object sender, EventArgs e)
{
setExcelReport();
}
protected void setExcelReport()
{
StringWriter sw = new StringWriter();
string sSQL = "";
//sw.WriteLine("结算单位\t委托编号\t主提单号\t分提单号\t船名\t航次\tETD\t目的港\t揽货人\t应收RMB\t实收RMB\t应收USD\t实收USD\t余额");
sw.WriteLine(this.hdNAMES.Value.Trim());
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet DS = T_ALL_DA.GetAllSQL(this.hdSQL.Value.Trim());
if (DS != null)
{
foreach (DataTable myTable in DS.Tables)
{
foreach (DataRow myRow in myTable.Rows)//遍历表
{
sSQL = "";
for (int i = 0; i < myTable.Columns.Count; i++)
{
if (sSQL.Trim() != "")
{
sSQL += "\t";
}
if (myRow[i].ToString() == null || myRow[i].ToString() == "")
{
sSQL += "";
if (sSQL.Trim() == "")
{
sSQL += "\t";
}
}
else
{
sSQL += myRow[i].ToString().Trim();
}
}
sw.WriteLine(sSQL);
}
}
//
sw.Close();
switch ("MUEXCEL")
{
case "MUEXCEL":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xls");
Response.ContentType = "application/ms-excel";
break;
case "MUTEXT":
Response.AddHeader("Content-Disposition", "attachment; filename=report.txt");
Response.ContentType = "application/txt";
break;
case "MUWORD":
Response.AddHeader("Content-Disposition", "attachment; filename=report.doc");
Response.ContentType = "application/ms-word";
break;
case "MUPDF":
Response.AddHeader("Content-Disposition", "attachment; filename=report.pdf");
Response.ContentType = "application/pdf";
break;
case "MUXML":
Response.AddHeader("Content-Disposition", "attachment; filename=report.xml");
Response.ContentType = "application/xml";
break;
}
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
}
}
private HttpFileCollection files;
private int fileCount;
protected void btExcel2_Click(object sender, EventArgs e)
{
string Extension = "";
string SavedName = "";
string upname = "";
string savedpath = "";
string realname = "";
string virtualname = "";
string path = "";
string OppPath = "TempFiles";
OppPath += "/";
string AbsPath = Server.MapPath(OppPath);
files = HttpContext.Current.Request.Files;
if (!Directory.Exists(Server.MapPath(OppPath)))
{
Directory.CreateDirectory(Server.MapPath(OppPath));
}
for (fileCount = 0; fileCount < files.Count; fileCount++)
{
HttpPostedFile postedFile = files[fileCount];
string fileName;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != string.Empty)
{
Extension = System.IO.Path.GetExtension(fileName);
if (Extension != ".xls")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('选择的文件类型不正确,只能为*.xls');</script>");
return;
}
else
{
try
{
////取上传文件的文件名
upname = System.IO.Path.GetFileName(fileName);
//系统自动产生的日期型文件名
SavedName = string.Format("{0:yyyyMMddHHmmss}", System.DateTime.Now);
////把文件保存到UploadFile文件中
//dvResult.InnerHtml += AbsPath + SavedName + upname;
postedFile.SaveAs(AbsPath + SavedName + upname);
//dvResult.InnerHtml += "&nbsp;true";
virtualname += OppPath + SavedName + upname + ",";
realname += upname + ",";
path = savedpath;
string strOldDb = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 5.0;Data Source=";
string sPath = AbsPath + SavedName + upname;
//dvResult.InnerHtml += strOldDb + AbsPath + SavedName + upname;
OleDbConnection OleCon = new OleDbConnection(strOldDb + AbsPath + SavedName + upname);
OleDbDataAdapter OleDAp = new OleDbDataAdapter("SELECT [FLAG],[LANE],[COUNTRY],[PORTDISCHARGE],[DESTINATION],[20GP1],[40GP1],[40HQ1],[40RH1],[45HQ1],[CARRIER],[ETD],[TT],[VIA],[SVC],[CARRIERLANE],[POC],[COMMODITY],[OWS],[EFFECTIVEDATE],[VALIDDATE],[REMARK],[20GP0],[40GP0],[40HQ0],[40RH0],[45HQ0],[PROFIT20GP1],[PROFIT40GP1],[PROFIT40HQ1],[PROFIT40RH1],[PROFIT45HQ1],[OF20GP],[OF40GP],[OF40HQ],[OF40RH],[OF45HQ],[BAF20GP],[BAF40GP],[BAF40HQ],[BAF40RH],[BAF45HQ],[CAF20GP],[CAF40GP],[CAF40HQ],[CAF40RH],[CAF45HQ],[PSS20GP],[PSS40GP],[PSS40HQ],[PSS40RH],[PSS45HQ],[GRI20GP],[GRI40GP],[GRI40HQ],[GRI40RH],[GRI45HQ],[INLAND20GP],[INLAND40GP],[INLAND40HQ],[INLAND40RH],[INLAND45HQ],[ISPS20GP],[ISPS40GP],[ISPS40HQ],[ISPS40RH],[ISPS45HQ],[SZ20GP],[SZ40GP],[SZ40HQ],[SZ40RH],[SZ45HQ],[AG20GP],[AG40GP],[AG40HQ],[AG40RH],[AG45HQ],[MODIFYTIME],[PIRICEVIAPORT],[PODLOAD],[20RS0],[20RS1],[PROFIT20RS1],[OF20RS],[BAF20RS],[CAF20RS],[PSS20RS],[GRI20RS],[INLAND20RS],[ISPS20RS],[SZ20RS],[AG20RS],[40NOR0],[40NOR1],[PROFIT40NOR1],[OF40NOR],[BAF40NOR],[CAF40NOR],[PSS40NOR],[GRI40NOR],[INLAND40NOR],[ISPS40NOR],[SZ40NOR],[AG40NOR] FROM [Sheet1$] where FLAG='Y'", OleCon);//,[20GP2],[40GP2],[40HQ2],[40RH2],[45HQ2],[20GP3],[40GP3],[40HQ3],[40RH3],[45HQ3],[PROFIT20GP2],[PROFIT40GP2],[PROFIT40HQ2],[PROFIT40RH2],[PROFIT45HQ2],[PROFIT20GP3],[PROFIT40GP3],[PROFIT40HQ3],[PROFIT40RH3],[PROFIT45HQ3],[20RS2],[20RS3],[PROFIT20RS2],[PROFIT20RS3],[40NOR2],[40NOR3],[PROFIT40NOR2],[PROFIT40NOR3]
DataSet ds = new DataSet();
OleDAp.Fill(ds);
//dvResult.InnerHtml += "&nbsp;true";
//this.GridView1.DataSource = ds;
//this.GridView1.DataBind();
if (ds == null)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('无符合条件的数据!');</script>");
}
else
{
CrmPriceCarrierDA CrmPriceCarrierDA = new CrmPriceCarrierDA();
int iResult = CrmPriceCarrierDA.InsertInfoExcel(ds, strUserID, strCompanyID);
if (iResult > 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('导入完毕!');</script>");
}
else if (iResult < 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key7", "<script>alert('格式错误,不能导入!');</script>");
}
}
File.Delete(AbsPath + SavedName + upname);
}
catch (Exception execError)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key11", "<script>alert('格式错误,不能导入!');</script>");
throw execError;
}
}
}
}
}
#region Grid参数
private void SaveColumnSetting(string tempColumnVal)
{
JsonColumnGroupEntity jsonColumnGroupEntity = GetPostEntity(tempColumnVal);
List<JsonColumnEntity> jsonColumnEntities = new List<JsonColumnEntity>();
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = userSettingDA.GetUserSettingByUserIDType(strUserID, strType);
if (userSettingEntity.GID != null)
{
userSettingEntity.ModifiedUser = strUserID;
GridEntity gridEntity = null;
List<GridColumnEntity> gridColumnEntities = new List<GridColumnEntity>();
gridEntity = GetSettingXml(userSettingEntity.Xml);
gridEntity.PagePreCount = jsonColumnGroupEntity.ShowCount;
foreach (JsonColumnEntity jColumn in jsonColumnGroupEntity.JsonColumnEntities)
{
foreach (GridColumnEntity gColumn in gridEntity.Columns)
{
if (gColumn.Description.Equals(jColumn.col3))
{
gColumn.Description = jColumn.col3;
gColumn.Width = jColumn.col5;
gColumn.Index = jColumn.col4;
if (jColumn.col6 != -1)
{
gColumn.VisibleState = jColumn.col6;
}
//gridColumnEntities.Add(gColumn);
break;
}
}
}
//Columns
//gridEntity.Columns = gridColumnEntities;
userSettingEntity.Xml = SaveUserSetting(gridEntity).OuterXml;
int iResult = userSettingDA.UpdateUserSetting(userSettingEntity);
}
else
{
if (jsonColumnGroupEntity != null)
{
userSettingEntity = new UserSettingEntity();
userSettingEntity.GID = Guid.NewGuid().ToString();
userSettingEntity.Name = "CrmPriceCarrierListGridSetting";
userSettingEntity.Description = "运价管理Grid设置";
userSettingEntity.UserID = strUserID;
userSettingEntity.Type = 1;//type值为1表示Grid
string strRequestUrl = Request.Url.ToString();
string strUrl = strRequestUrl.Substring(0, strRequestUrl.LastIndexOf("/"));
string strPage = strRequestUrl.Substring(strRequestUrl.LastIndexOf("/") + 1, strRequestUrl.Length - strRequestUrl.LastIndexOf("/") - 1);
userSettingEntity.Url = strUrl;
userSettingEntity.Page = strPage;
userSettingEntity.CreateUser = strUserID;
GridEntity gridEntity = new GridEntity();
gridEntity.GID = userSettingEntity.GID;
gridEntity.UserID = strUserID;
gridEntity.GroupBy = "";
gridEntity.DefaultPrePageCount = 15;
gridEntity.PagePreCount = jsonColumnGroupEntity.ShowCount;
List<GridColumnEntity> gridColumnEntities = new List<GridColumnEntity>();
foreach (JsonColumnEntity column in jsonColumnGroupEntity.JsonColumnEntities)
{
GridColumnEntity gridColumnEntity = new GridColumnEntity();
if (column.col6 != -1)
{
gridColumnEntity.Name = column.col2;
gridColumnEntity.VisibleState = column.col6;
}
else
{
switch (column.col3.Trim())
{
case "锁定":
gridColumnEntity.Name = "LOCKFLAG";
break;
case "发布":
gridColumnEntity.Name = "ISISSUE";
break;
case "船公司":
gridColumnEntity.Name = "CARRIER";
break;
case "起运港":
gridColumnEntity.Name = "PODLOAD";
break;
case "卸货港":
gridColumnEntity.Name = "PORTDISCHARGE";
break;
case "目的地":
gridColumnEntity.Name = "DESTINATION";
break;
case "中转港":
gridColumnEntity.Name = "VIA";
break;
case "ETD":
gridColumnEntity.Name = "ETD";
break;
case "航程":
gridColumnEntity.Name = "TT";
break;
case "航线":
gridColumnEntity.Name = "LANE";
break;
case "20GP(成本)":
gridColumnEntity.Name = "D_20GP0";
break;
case "40GP(成本)":
gridColumnEntity.Name = "D_40GP0";
break;
case "40HQ(成本)":
gridColumnEntity.Name = "D_40HQ0";
break;
case "40RH(成本)":
gridColumnEntity.Name = "D_40RH0";
break;
case "45HQ(成本)":
gridColumnEntity.Name = "D_45HQ0";
break;
case "20GP(卖价)":
gridColumnEntity.Name = "D_20GP1";
break;
case "40GP(卖价)":
gridColumnEntity.Name = "D_40GP1";
break;
case "40HQ(卖价)":
gridColumnEntity.Name = "D_40HQ1";
break;
case "40RH(卖价)":
gridColumnEntity.Name = "D_40RH1";
break;
case "45HQ(卖价)":
gridColumnEntity.Name = "D_45HQ1";
break;
case "超重费":
gridColumnEntity.Name = "OWS";
break;
case "生效期":
gridColumnEntity.Name = "EFFECTIVEDATE";
break;
case "有效期":
gridColumnEntity.Name = "VALIDDATE";
break;
case "品名":
gridColumnEntity.Name = "COMMODITY";
break;
case "备注":
gridColumnEntity.Name = "REMARK";
break;
case "分公司":
gridColumnEntity.Name = "CORPID";
break;
}
gridColumnEntity.VisibleState = 0;
}
gridColumnEntity.Description = column.col3;
gridColumnEntity.Index = column.col4;
gridColumnEntity.Width = column.col5;
gridColumnEntities.Add(gridColumnEntity);
}
//Columns
gridEntity.Columns = gridColumnEntities;
userSettingEntity.Xml = SaveUserSetting(gridEntity).OuterXml;
int iResult = userSettingDA.InsertUserSetting(userSettingEntity);
dvSaveState.InnerHtml = iResult.ToString();
}
}
}
#region 获取列信息
/// <summary>
/// 获取列信息
/// </summary>
/// <param name="tempValue"></param>
/// <returns></returns>
private JsonColumnGroupEntity GetPostEntity(string tempValue)
{
JsonColumnGroupEntity tempColumnGroupEntity = new JsonColumnGroupEntity();
try
{
tempColumnGroupEntity = (JsonColumnGroupEntity)JSON.Instance.ToObject(tempValue);
}
catch (Exception error)
{
throw error;
}
return tempColumnGroupEntity;
}
#endregion
private XmlDocument SaveUserSetting(GridEntity gridEntity)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("user-settings");
//xmlDoc.AppendChild(root);
XmlElement xGid = xmlDoc.CreateElement("gid");
xGid.InnerText = gridEntity.GID;
root.AppendChild(xGid);
XmlElement xUserID = xmlDoc.CreateElement("userid");
xUserID.InnerText = gridEntity.UserID;
root.AppendChild(xUserID);
XmlElement xCreateTime = xmlDoc.CreateElement("create-time");
xCreateTime.InnerText = gridEntity.CreateTime.ToString();
root.AppendChild(xCreateTime);
XmlElement xColumns = xmlDoc.CreateElement("columns");
foreach (GridColumnEntity column in gridEntity.Columns)
{
XmlElement xColumn = xmlDoc.CreateElement("column");
XmlElement nName = xmlDoc.CreateElement("name");
nName.InnerText = column.Name;
xColumn.AppendChild(nName);
XmlElement nDescription = xmlDoc.CreateElement("description");
nDescription.InnerText = column.Description;
xColumn.AppendChild(nDescription);
XmlElement nIndex = xmlDoc.CreateElement("index");
nIndex.InnerText = column.Index.ToString();
xColumn.AppendChild(nIndex);
XmlElement nWidth = xmlDoc.CreateElement("width");
nWidth.InnerText = column.Width.ToString();
xColumn.AppendChild(nWidth);
XmlElement nVisible = xmlDoc.CreateElement("visible");
nVisible.InnerText = column.VisibleState.ToString();
xColumn.AppendChild(nVisible);
xColumns.AppendChild(xColumn);
}
root.AppendChild(xColumns);
XmlElement xGroupBy = xmlDoc.CreateElement("group-by");
xGroupBy.InnerText = gridEntity.GroupBy;
root.AppendChild(xGroupBy);
XmlElement xPage = xmlDoc.CreateElement("page");
XmlElement nPageDefault = xmlDoc.CreateElement("page-default");
nPageDefault.InnerText = gridEntity.DefaultPrePageCount.ToString();
xPage.AppendChild(nPageDefault);
XmlElement nPagePre = xmlDoc.CreateElement("page-pre");
nPagePre.InnerText = gridEntity.PagePreCount.ToString();
xPage.AppendChild(nPagePre);
root.AppendChild(xPage);
xmlDoc.AppendChild(root);
return xmlDoc;
}
private GridEntity GetSettingXml(string strXml)
{
XmlDocument xmlSettingDoc = new XmlDocument();
GridEntity gridEntity = new GridEntity();
try
{
xmlSettingDoc.LoadXml(strXml);
gridEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[0].InnerText.Trim();
gridEntity.UserID = xmlSettingDoc.ChildNodes[0].ChildNodes[1].InnerText.Trim();
gridEntity.CreateTime = DateTime.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[2].InnerText.Trim());
IList<GridColumnEntity> columnsEntities = new List<GridColumnEntity>();
int iColCount = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes.Count;
for (int i = 0; i < iColCount; i++)
{
GridColumnEntity columnEntity = new GridColumnEntity();
//columnEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[0].ToString();
columnEntity.Name = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[0].InnerText.Trim();
columnEntity.Description = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[1].InnerText.Trim();
columnEntity.Index = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[2].InnerText.Trim());
columnEntity.Width = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[3].InnerText.Trim());
columnsEntities.Add(columnEntity);
}
gridEntity.Columns = columnsEntities;
gridEntity.GroupBy = xmlSettingDoc.ChildNodes[0].ChildNodes[4].InnerText.Trim();
gridEntity.DefaultPrePageCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[0].InnerText.Trim());
gridEntity.PagePreCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[1].InnerText.Trim());
}
catch (Exception error)
{
throw (error);
}
return gridEntity;
}
public enum SqlName
{
NAME = 0,
LOGTYPE = 1,
LOGTIME = 2,
LOGCONTENT = 3,
USERNAME = 4
}
#endregion
}
}