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

440 lines
19 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.Text;
using DSWeb.DataAccess;
using System.Data.SqlClient;
using DSWeb.Models;
using DSWeb.EntityDA;
using System.Web.Script.Serialization;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;
using DSWeb.Authority;
namespace DSWeb.Shipping
{
public partial class ExchangesUnitContract : System.Web.UI.Page
{
public string strHandleType = String.Empty;
public string sSQL = String.Empty;
public string gvid = String.Empty;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
InfoClientContractDA InfoClientContractDA = new InfoClientContractDA();
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();
hdUserID.Value = strUserID.Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
//
if (!IsPostBack)
{
if (Request.QueryString["handle"] != null)
{
ViewState["strHandleType"] = Request.QueryString["handle"].ToString();
strHandleType = ViewState["strHandleType"].ToString().Trim();
if (Request.QueryString["id"] != null)
{
ViewState["GID"] = Request.QueryString["id"].ToString();
this.hdGid.Value = ViewState["GID"].ToString().Trim();
}
if (Request.QueryString["LINKID"] != null)
{
ViewState["LINKID"] = Request.QueryString["LINKID"].ToString();
}
//
switch (strHandleType)
{
case "add"://新增
ViewState["GID"] = getBSNO("Cont");
this.hdGid.Value = ViewState["GID"].ToString().Trim();
//
tbCONTRACTNO.Value = "";
tbCHIEF.Value = "";
tbSIGNINGDATE.Value = "";
tbSTARTDATE.Value = "";
tbCANCELDATE.Value = "";
tbREMARK.Value = "";
this.hd_comboSubcompany.Value = "";
this.hd_comboDept.Value = "";
break;
case "edit"://录入
InfoClientContractEntity model = new InfoClientContractEntity();
model = InfoClientContractDA.GetModel(ViewState["GID"].ToString().Trim());
//
if (model == null)
{
return;
}
tbCONTRACTNO.Value = model.CONTRACTNO.ToString().Trim();
tbCHIEF.Value = model.CHIEF.ToString().Trim();
tbSIGNINGDATE.Value = model.SIGNINGDATE.ToString().Trim() == "0001-1-1 0:00:00" ? "" : model.SIGNINGDATE.ToString().Trim().Replace(" 0:00:00", "");
tbSTARTDATE.Value = model.STARTDATE.ToString().Trim() == "0001-1-1 0:00:00" ? "" : model.STARTDATE.ToString().Trim().Replace(" 0:00:00", "");
tbCANCELDATE.Value = model.CANCELDATE.ToString().Trim() == "0001-1-1 0:00:00" ? "" : model.CANCELDATE.ToString().Trim().Replace(" 0:00:00", "");
tbREMARK.Value = model.REMARK.ToString().Trim();
this.hd_comboSubcompany.Value = T_ALL_DA.GetStrSQL("CORPNAME", "select top 1 [NAME] as CORPNAME from [company] where gid='" + model.CORPID.ToString().Trim() + "'");
this.hd_comboDept.Value = T_ALL_DA.GetStrSQL("DEPTNAME", "select top 1 [DEPTNAME] from [sys_dept] where gid='" + model.DEPTGID.ToString().Trim() + "'");
//
//权限可视范围
string strV = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modExchangesUnit");
string strO = RangeDA.GetOPERATERANGE(strUserID.Trim(), "modExchangesUnit");
string alt = "";
if (strV.Trim().Equals("4"))//全部
{
ibAdd.Enabled = true;
}
else if (strV.Trim().Equals("1"))//分公司
{
if (strO.Trim().Equals("1"))//公司
{
alt = RangeDA.GetUnitCompany(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("3"))//个人
{
alt = RangeDA.GetUnitPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
}
else if (strV.Trim().Equals("3"))
{
if (strO.Trim().Equals("3"))//个人
{
alt = RangeDA.GetUnitPerson(strUserID.Trim(), ViewState["LINKID"].ToString().Trim());
if (alt == "")
{
getEnabled();
}
}
else if (strO.Trim().Equals("4"))//无
{
getEnabled();
}
}
//
break;
}
}
else
{
}
}
//
if (this.hdEnter.Value == "0")
{
getEnter();
}
else if (this.hdEnter.Value == "1")
{
setDelAll();
}
//
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key", "<script>initComboSubcompany();initComboDept();</script>");
}
protected void getEnabled()
{
this.hdEnabled.Value = "1";
ibAdd.Enabled = false;
divEnter.Disabled = true;
iDel.Disabled = true;
//
tbCONTRACTNO.Disabled = true;
tbCHIEF.Disabled = true;
tbSIGNINGDATE.Disabled = true;
tbSTARTDATE.Disabled = true;
tbCANCELDATE.Disabled = true;
tbREMARK.Disabled = true;
//
FileUpload1.Enabled = false;
btFU1.Disabled = true;
imgDel.Disabled = true;
mygrid_container_log.Disabled = true;
}
protected String getBSNO(string sGID)
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = sGID + strBSNO;
return strBSNO;
}
protected bool getAdd()
{
InfoClientContractEntity model = new InfoClientContractEntity();
model.GID = ViewState["GID"].ToString().Trim();
model.CREATEUSER = strUserID;
model.MODIFIEDUSER = strUserID;
model.LINKID = ViewState["LINKID"].ToString().Trim();
model.CONTRACTNO = tbCONTRACTNO.Value.Trim();
model.SIGNINGDATE = tbSIGNINGDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbSIGNINGDATE.Value.Trim());
model.STARTDATE = tbSTARTDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbSTARTDATE.Value.Trim());
model.CANCELDATE = tbCANCELDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbCANCELDATE.Value.Trim());
model.CHIEF = tbCHIEF.Value.Trim();
model.REMARK = tbREMARK.Value.Trim();
string CORPID = T_ALL_DA.GetStrSQL("gid", "select top 1 gid from [company] where [NAME]='" + this.hd_comboSubcompany.Value.Trim() + "'");
string DEPTGID = T_ALL_DA.GetStrSQL("gid", "select top 1 gid from [sys_dept] where [DEPTNAME]='" + this.hd_comboDept.Value.Trim() + "' and LINKID='" + CORPID.Trim() + "'");
model.CORPID = CORPID;
model.DEPTGID = DEPTGID;
int ialt = InfoClientContractDA.Add(model);
if (ialt == 1)
{
ViewState["strHandleType"] = "edit";
return true;
}
else
{
return false;
}
}
protected bool getEdit()
{
InfoClientContractEntity model = new InfoClientContractEntity();
model.GID = ViewState["GID"].ToString().Trim();
model.MODIFIEDUSER = strUserID;
model.CONTRACTNO = tbCONTRACTNO.Value.Trim();
model.SIGNINGDATE = tbSIGNINGDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbSIGNINGDATE.Value.Trim());
model.STARTDATE = tbSTARTDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbSTARTDATE.Value.Trim());
model.CANCELDATE = tbCANCELDATE.Value.Trim() == "" ? DateTime.Parse("0001-01-01") : DateTime.Parse(tbCANCELDATE.Value.Trim());
model.CHIEF = tbCHIEF.Value.Trim();
model.REMARK = tbREMARK.Value.Trim();
string CORPID = T_ALL_DA.GetStrSQL("gid", "select top 1 gid from [company] where [NAME]='" + this.hd_comboSubcompany.Value.Trim() + "'");
string DEPTGID = T_ALL_DA.GetStrSQL("gid", "select top 1 gid from [sys_dept] where [DEPTNAME]='" + this.hd_comboDept.Value.Trim() + "' and LINKID='" + CORPID.Trim() + "'");
model.CORPID = CORPID;
model.DEPTGID = DEPTGID;
//model.CREATEUSER = strShowName;
//model.LINKID = ViewState["LINKID"].ToString().Trim();
int ialt = InfoClientContractDA.Update(model);
if (ialt == 1)
{
return true;
}
else
{
return false;
}
}
protected void getEnter()
{
string strError = getFU();
if (strError.Trim() != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>alert('" + strError.Trim() + "');</script>");
return;
}
//
bool bl = false;
strHandleType = ViewState["strHandleType"].ToString();
if (strHandleType.Equals("add"))//新增
{
bl = getAdd();
}
else if (strHandleType.Equals("edit"))//录入
{
bl = getEdit();
}
//
iDel.Disabled = false;
ibAdd.Enabled = true;
this.hdEnter.Value = "";
//
if (bl)
{
ViewState["strHandleType"] = "edit";
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>reloadParent('" + ViewState["GID"].ToString().Trim() + "','" + ViewState["strHandleType"].ToString().Trim() + "');</script>");
return;
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('出错,请重新填写!');</script>");
return;
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
ViewState["strHandleType"] = "add";
ViewState["GID"] = getBSNO("Cont");
this.hdGid.Value = ViewState["GID"].ToString().Trim();
//
tbCONTRACTNO.Value = "";
tbCHIEF.Value = "";
tbSIGNINGDATE.Value = "";
tbSTARTDATE.Value = "";
tbCANCELDATE.Value = "";
tbREMARK.Value = "";
this.hd_comboSubcompany.Value = "";
this.hd_comboDept.Value = "";
//
iDel.Disabled = true;
ibAdd.Enabled = true;
divEnter.Disabled = false;
}
protected void setDelAll()
{
this.hdEnter.Value = "";
int ialt = InfoClientContractDA.Delete(ViewState["GID"].ToString().Trim());
if (ialt != 1)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('操作失败!');</script>");
return;
}
else
{
setDel(ViewState["GID"].ToString().Trim());
Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('删除成功!');window.opener.location.reload();</script>");
}
//
ViewState["strHandleType"] = "add";
ViewState["GID"] = getBSNO("Cont");
this.hdGid.Value = ViewState["GID"].ToString().Trim();
//
tbCONTRACTNO.Value = "";
tbCHIEF.Value = "";
tbSIGNINGDATE.Value = "";
tbSTARTDATE.Value = "";
tbCANCELDATE.Value = "";
tbREMARK.Value = "";
this.hd_comboSubcompany.Value = "";
this.hd_comboDept.Value = "";
//
iDel.Disabled = true;
ibAdd.Enabled = false;
}
private string setDel(string sGids)
{
string strs = "";
string alt = "";
string[] itmes = sGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < itmes.Length; i++)
{
strs += " or LINKGID='" + itmes[i].ToString().Trim() + "'";
}
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string sSQL = "select * from op_sailingdateurl where (1<0 " + strs + ") and TABLENAME='info_client_contract'";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
string funame = "";
//
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
funame = ds.Tables[0].Rows[i]["AFFIXNAME"].ToString().Trim();
string AbsPath = Server.MapPath("FTPFiles/");
string sPath = AbsPath + funame;
File.Delete(sPath);
}
}
//
sSQL = "delete from op_sailingdateurl where (1<0 " + strs + ") and TABLENAME='info_client_contract'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
if (!bl)
{
alt = "操作出错!";
}
return alt;
}
public bool IsNumeric(string s)
{
bool bReturn = true;
try
{
int inum = int.Parse(s);
}
catch
{
bReturn = false;
}
return bReturn;
}
protected string getFU()
{
if (FileUpload1.HasFile == true)//如果用户确实选择了上传控件的浏览按钮,浏览文件成功.
{
string fuName = FileUpload1.FileName.Replace(" ", "_");
string AbsPath = Server.MapPath("FTPFiles/");
string sPath = AbsPath + fuName;
Int32 FileLength = 0;//有可能图片的大小会超出INT的范围所以声明为Int32,当然这和下面大小的判断有关系
FileLength = this.FileUpload1.PostedFile.ContentLength;//获取上传文件的字节大小
//取web中的最大限制数FTPMaxRequestLength
string strFTPMaxRequestLength = System.Configuration.ConfigurationSettings.AppSettings["FTPMaxRequestLength"].ToString() as string;
Int32 iFTPMaxRequestLength = 2091151;
if (strFTPMaxRequestLength == null)
{
iFTPMaxRequestLength = Int32.Parse(strFTPMaxRequestLength);
}
//
if (FileLength > iFTPMaxRequestLength)
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key4", "<script>alert('文件最大不能超过4M');</script>");
return "上传文件超过最大限制!";
}
if (File.Exists(sPath)) //判断文件是否寸在
{
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('文件上传FTP失败');</script>");
return "当前路径下已经存在同名文件!";
}
this.FileUpload1.SaveAs(sPath); //保存到服务器的目录,需要根据服务器具体情况修改FileUpload1.FileName会自动获取上传文件名.
OpSailingDateDA OpSailingDateDA = new EntityDA.OpSailingDateDA();
OpSailingDateUrlEntity OpSailingDateUrlEntity = new Models.OpSailingDateUrlEntity();
OpSailingDateUrlEntity.GID = getBSNO("CUrl");// 惟一编号
OpSailingDateUrlEntity.LINKGID = ViewState["GID"].ToString().Trim();// 关联编号
OpSailingDateUrlEntity.AFFIXNAME = fuName;// 附件名称
OpSailingDateUrlEntity.AFFIXURL = "../Shipping/FTPFiles/" + fuName;// 附件地址
OpSailingDateUrlEntity.AFFIXSIZE = FileLength.ToString().Trim();// 附件大小
OpSailingDateUrlEntity.TABLENAME = "info_client_contract";//
int iResult = OpSailingDateDA.InserInfo(OpSailingDateUrlEntity);
//
//File.Delete(sPath);
}
return "";
}
}
}