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

369 lines
15 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.ComponentModel;
using System.Drawing;
using System.Web.SessionState;
using System.Web.Mail;
using System.IO;
using System.Data.OleDb;
using JsonHelper;
using DSWeb.Log;
namespace DSWeb.ParameterSet
{
public partial class CodeVoynoSetInfo : System.Web.UI.Page
{
public string sSQL = String.Empty;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
public string strdate;//用户GID
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;
}
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 (this.hdGid.Value != null)
{
if (this.hdEnter.Value != "")
{
getEnter();
}
}
//
if (!IsPostBack)
{
if (Request.QueryString["vsid"] != null)
{
this.hdVSID.Value = Request.QueryString["vsid"].ToString();
tbVESSEL.Text = T_ALL_DA.GetStrSQL("VESSEL", "select VESSEL from code_vessel where VSID='" + this.hdVSID.Value + "'");
}
else
{
if (Request.QueryString["vessel"] != null)
{
string strVESSEL = Request.QueryString["vessel"].ToString();
this.hdVSID.Value = T_ALL_DA.GetStrSQL("VSID", "select VSID from code_vessel where vessel='" + strVESSEL + "'");
tbVESSEL.Text = strVESSEL.Trim();
}
}
if (Request.QueryString["id"] != null)
{
this.hdGid.Value = Request.QueryString["id"].ToString();
}
if (Request.QueryString["handle"] != null)
{
this.hdHandleType.Value = Request.QueryString["handle"].ToString();
}
//
if (this.hdHandleType.Value.Trim() != "")
{
switch (this.hdHandleType.Value.Trim())
{
case "add"://新增
this.hdGid.Value = getBSNO();
this.hdGid.Value = this.hdGid.Value.ToString().Trim();
getClear();
//
ibDel.Enabled = false;
ibAdd.Enabled = false;
break;
case "edit"://录入
getDataSet("select *,VESSEL=(select VESSEL from code_vessel where VSID='" + this.hdVSID.Value + "') from code_voyno where VOID='" + this.hdGid.Value.Trim() + "'");
//
ibDel.Enabled = true;
ibAdd.Enabled = true;
break;
}
}
else
{
}
}
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>initComboPORTLOAD();initComboPORTDISCHARGE();initComboENTREPORT();initComboYARD();</script>");
}
protected void getClear()
{
//tbVESSEL.Text = "";
tbVOYNO.Text = "";
this.hd_comboPORTLOAD.Value = "";
tbETD.Text = "";
this.hd_comboENTREPORT.Value = "";
tbCLOSINGDATE.Text = "";
this.hd_comboPORTDISCHARGE.Value = "";
tbETA.Text = "";
this.hd_comboYARD.Value = "";
}
protected void getDataSet(string str)
{
DataSet ds = T_ALL_DA.GetAllSQL(str);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
this.hdGid.Value = ds.Tables[0].Rows[0]["VOID"].ToString().Trim();
tbVESSEL.Text = ds.Tables[0].Rows[0]["VESSEL"].ToString().Trim();
tbVOYNO.Text = ds.Tables[0].Rows[0]["VOYNO"].ToString().Trim();
this.hd_comboPORTLOAD.Value = ds.Tables[0].Rows[0]["PORTLOAD"].ToString().Trim();
this.hd_comboENTREPORT.Value = ds.Tables[0].Rows[0]["ENTREPORT"].ToString().Trim();
this.hd_comboPORTDISCHARGE.Value = ds.Tables[0].Rows[0]["PORTDISCHARGE"].ToString().Trim();
this.hd_comboYARD.Value = ds.Tables[0].Rows[0]["YARDID"].ToString().Trim();
//
string strETD = ds.Tables[0].Rows[0]["ETD"].ToString().Trim();
if (strETD.Trim().Equals("") || strETD.Trim().IndexOf("0001")>-1)
{
tbETD.Text = "";
}
else
{
tbETD.Text = DateTime.Parse(strETD.Trim()).ToString("yyyy-MM-dd");
}
//
string strCLOSINGDATE = ds.Tables[0].Rows[0]["CLOSINGDATE"].ToString().Trim();
if (strCLOSINGDATE.Trim().Equals("") || strCLOSINGDATE.Trim().IndexOf("0001")>-1)
{
tbCLOSINGDATE.Text = "";
}
else
{
tbCLOSINGDATE.Text = DateTime.Parse(strCLOSINGDATE.Trim()).ToString("yyyy-MM-dd HH:mm");
}
//
string strETA = ds.Tables[0].Rows[0]["ETA"].ToString().Trim();
if (strETA.Trim().Equals("") || strETA.Trim().IndexOf("0001")>-1)
{
tbETA.Text = "";
}
else
{
tbETA.Text = DateTime.Parse(strETA.Trim()).ToString("yyyy-MM-dd");
}
}
else
{
getClear();
}
}
else
{
getClear();
}
}
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "VSID" + strBSNO;
return strBSNO;
}
protected bool getAdd()
{
sSQL = "insert into code_voyno(VOID,VESSEL,VSID,VOYNO,PORTLOAD,ENTREPORT,PORTDISCHARGE,ETD,CLOSINGDATE,ETA,CORPID,YARDID) values('" + this.hdGid.Value.ToString().Trim() + "','" + this.tbVESSEL.Text + "','" + this.hdVSID.Value.Trim() + "','" + tbVOYNO.Text.Trim() + "','" + this.hd_comboPORTLOAD.Value.Trim() + "','" + this.hd_comboENTREPORT.Value.Trim() + "','" + this.hd_comboPORTDISCHARGE.Value.Trim() + "'";
if(tbETD.Text.Trim() == "")
{
sSQL += ",null";
}
else
{
sSQL += ",'" + tbETD.Text.Trim() + "'";
}
if(tbCLOSINGDATE.Text.Trim() == "")
{
sSQL += ",null";
}
else
{
sSQL += ",'" + tbCLOSINGDATE.Text.Trim() + "'";
}
if(tbETA.Text.Trim() == "")
{
sSQL += ",null";
}
else
{
sSQL += ",'" + tbETA.Text.Trim() + "'";
}
sSQL += ",'" + strCompanyID.Trim()+ "','" + this.hd_comboYARD.Value.Trim() + "')";
//
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
if (bl)
{
return true;
}
else
{
return false;
}
}
protected bool getEdit()
{
sSQL = "update code_voyno set VOYNO='" + tbVOYNO.Text.Trim() + "',PORTLOAD='" + this.hd_comboPORTLOAD.Value.Trim() + "',ENTREPORT='" + this.hd_comboENTREPORT.Value.Trim() + "',PORTDISCHARGE='" + this.hd_comboPORTDISCHARGE.Value.Trim() + "',YARDID='" + this.hd_comboYARD.Value.Trim() + "'";
if (tbETD.Text.Trim() == "")
{
sSQL += ",ETD=null";
}
else
{
sSQL += ",ETD='" + tbETD.Text.Trim() + "'";
}
if (tbCLOSINGDATE.Text.Trim() == "")
{
sSQL += ",CLOSINGDATE=null";
}
else
{
sSQL += ",CLOSINGDATE='" + tbCLOSINGDATE.Text.Trim() + "'";
}
if (tbETA.Text.Trim() == "")
{
sSQL += ",ETA=null";
}
else
{
sSQL += ",ETA='" + tbETA.Text.Trim() + "'";
}
sSQL += " where VOID='" + this.hdGid.Value.ToString().Trim() + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(sSQL);
if (bl)
{
this.hdHandleType.Value = "edit";
return true;
}
else
{
return false;
}
}
protected void getEnter()
{
if (tbVESSEL.Text.Trim() == "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key2", "<script>alert('船名英文名称不允许为空!');</script>");
//Response.Write("<script>alert('船名英文名称不允许为空!');</script>");
return;
}
//
string strls = "";
bool bl = false;
if (this.hdHandleType.Value.Trim().Equals("add"))//新增
{
strls = T_ALL_DA.GetStrSQL("VESSEL", "select VESSEL from code_voyno where VESSEL='" + tbVESSEL.Text.Trim() + "'");
if (strls.Trim() != "")
{
//Response.Write("<script>alert('船名英文名称不允许重复!');</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('船名英文名称不允许重复!');</script>");
return;
}
bl = getAdd();
}
else if (this.hdHandleType.Value.Trim().Equals("edit"))//录入
{
strls = T_ALL_DA.GetStrSQL("VESSEL", "select VESSEL from code_voyno where VESSEL='" + tbVESSEL.Text.Trim() + "' and VESSELID<>'" + this.hdGid.Value.ToString().Trim() + "'");
if (strls.Trim() != "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('船名英文名称不允许重复!');</script>");
//Response.Write("<script>alert('船名英文名称不允许重复!');</script>");
return;
}
bl = getEdit();
}
//
if (bl)
{
//
ibDel.Enabled = true;
ibAdd.Enabled = true;
//
Page.ClientScript.RegisterStartupScript(this.GetType(), "key10", "<script>reloadParent('" + this.hdGid.Value.ToString().Trim() + "','" + this.hdHandleType.Value.Trim() + "');</script>");
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key5", "<script>alert('操作成功!');window.opener.location.reload();history.back();</script>");
//Response.Write("<script>alert('操作成功!');window.opener.location.reload();history.back();</script>");
return;
}
else
{
//Response.Write("<script>alert('出错,请重新填写!');</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), "key6", "<script>alert('出错,请重新填写!');</script>");
return;
}
}
protected void ibAdd_Click(object sender, EventArgs e)
{
this.hdHandleType.Value = "add";
this.hdGid.Value = getBSNO();
this.hdGid.Value = this.hdGid.Value.ToString().Trim();
getClear();
//
ibDel.Enabled = false;
ibAdd.Enabled = false;
}
protected void ibDel_Click(object sender, EventArgs e)
{
bool bl = T_ALL_DA.GetExecuteSqlCommand("delete from code_voyno where VOID='" + this.hdGid.Value.ToString().Trim() + "'");
if (bl)
{
this.hdHandleType.Value = "edit";
getDataSet("select top 1 *,VESSEL=(select VESSEL from code_vessel where VSID='" + this.hdVSID.Value + "') from code_voyno where VSID='" + this.hdVSID.Value.Trim() + "' order by VOYNO");
//
ibDel.Enabled = true;
ibAdd.Enabled = true;
//
Page.ClientScript.RegisterStartupScript(this.GetType(), "key9", "<script>reloadParent('" + this.hdGid.Value.ToString().Trim() + "','del');</script>");
//Page.ClientScript.RegisterStartupScript(this.GetType(), "key7", "<script>alert('删除成功!');window.opener.location.reload();history.back();</script>");
//Response.Write("<script>alert('删除成功!');window.opener.location.reload();history.back();</script>");
return;
}
else
{
//
ibDel.Enabled = true;
ibAdd.Enabled = true;
Page.ClientScript.RegisterStartupScript(this.GetType(), "key8", "<script>alert('删除出错!');</script>");
//Response.Write("<script>alert('删除出错!');</script>");
return;
}
}
}
}