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.

176 lines
6.9 KiB
C#

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;
using DSWeb.Attributes;
using WebSqlHelper;
namespace DSWeb.box
{
public partial class BoxEdit : System.Web.UI.Page
{
protected string cmd,id;
protected void Page_Load(object sender, EventArgs e)
{
cmd = Request["handle"];
id = Request["id"];
if (!IsPostBack)
{
HttpHelper.BindDropDownList(CntrOwner, BaseClass.db.GetSqlStrTable("select * from info_client where ISCARRIER = 1"), "shortname", "codename", 1);
HttpHelper.BindDropDownList(Cntype, BaseClass.db.GetSqlStrTable("select * from code_ctn"), "ctn", "ctn", 1);
if (cmd == "edit")
{
CheckBox1.Visible = true;
CreateData();
hfCntrNo.Value=cntrno.Text;
}
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>initComboPort();</script>");
}
void CreateData()
{
DataRow dr = BaseClass.db.GetSqlStrRow("select * from container_info where Cntrid="+id);
if (dr != null)
{
BaseClass.InitValue(CntrOwner, dr);
//try
//{
// hd_comboPORT.Value = BaseClass.db.GetSpScalar("select cname from code_disport where portid= '" + dr["position"].ToString() + "'").ToString();
//}catch { }
hd_comboPORT.Value = getPortName(dr["position"].ToString());
hd_port.Value = dr["position"].ToString();
Buytime.Text = DateHelper.dateFormat(dr["buytime"].ToString(),"yyyy-MM-dd");
Rent_begintime.Text = DateHelper.dateFormat(dr["Rent_begintime"].ToString(), "yyyy-MM-dd");
Rent_endtime.Text = DateHelper.dateFormat(dr["Rent_endtime"].ToString(), "yyyy-MM-dd");
tbREMARK.Text = dr["REMARK"].ToString();
}
}
protected void ibsave_Click(object sender, ImageClickEventArgs e)
{
if (string.IsNullOrEmpty(cntrno.Text.Trim()))
{
Alert("请输入箱号");
return;
}
if (!WebSqlHelper.Common.isCntrNO(cntrno.Text))
{
Alert("错误的箱号,请重新输入");
return;
}
string posi = Request["ddlPORT"].ToString();
string Status = Request["Status"].ToString();
string s1 = "", s2 = "", s3 = "";
DataTable dtstruct = BaseClass.db.GetSqlStrTable("select * from container_info where 1>2");
List<System.Data.Common.DbParameter> param = new List<System.Data.Common.DbParameter>();
BaseClass.CreateSql(cntrno, dtstruct, ref s1, ref s2, ref s3, ref param);
string insert = "insert into container_info (" + s1.TrimEnd(',') + ",position,positionname,REMARK) values (" + s2.TrimEnd(',') + ",@position,@positionname,'" + tbREMARK.Text.Trim() + "')";
string edit = "update container_info set " + s3.TrimEnd(',') + ",position=@position,positionname=@positionname,REMARK='" + tbREMARK.Text.Trim() + "' where cntrid=@id";
param.Add(BaseClass.db.GetParameter("position", posi));
param.Add(BaseClass.db.GetParameter("positionname", hd_comboPORT.ToString()));
if (cmd == "edit")
{
if (BaseClass.db.GetSqlStrTable("select * from container_info where CntrNo='" + cntrno.Text.Trim() + "' and cntrid!=" + id).Rows.Count > 0)
{
Alert("此箱号的箱子已经录入");
return;
}
param.Add(BaseClass.db.GetParameter("id", id));
BaseClass.db.SetSqlStrNonQuery(edit, param.ToArray());
if (CheckBox1.Checked)
{
BaseClass.db.SetSqlStrNonQuery("update container_business set Box_No='"+cntrno.Text+"' where box_no='"+hfCntrNo.Value+"'");
}
if (Status.ToString()=="5")
{
BaseClass.db.SetSqlStrNonQuery("update container_info set Vessel='',Voyage='' where cntrno='" + hfCntrNo.Value + "'");
}
}
else if (cmd == "add")
{
if (BaseClass.db.GetSqlStrTable("select * from container_info where CntrNo='" + cntrno.Text.Trim() + "'").Rows.Count > 0)
{
Alert("此箱号的箱子已经录入");
return;
}
BaseClass.db.SetSqlStrNonQuery(insert, param.ToArray());
}
Alert2("已保存成功");
}
protected void ibAdd_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("BoxEdit.aspx?handle=add");
}
public string getPortName(string portid)
{
string str = "";
try
{
DataRow dr = BaseClass.db.GetSqlStrRow("select * from code_disport where portid='" + portid + "'");
if (dr != null)
{
str = dr["PORT"].ToString().Trim();
// str = dr["PORT"].ToString().Trim() + "-" + dr["cname"].ToString().Trim();
}
}
catch { }
return str;
}
// Methods
public void Alert(string msg)
{
ScriptManager.RegisterClientScriptBlock(this, base.GetType(), WebSqlHelper.Common.RndNum(8), "alert('" + msg + "');", true);
}
public void Alert2(string msg)
{
ScriptManager.RegisterClientScriptBlock(this, base.GetType(), WebSqlHelper.Common.RndNum(8), "alert('" + msg + "');window.parent.opener.location.href = window.parent.opener.location.href;", true);
}
public void Run(string script)
{
ScriptManager.RegisterClientScriptBlock(this, base.GetType(), WebSqlHelper.Common.RndNum(8), script, true);
}
public void ShowMessageAndRedirect(string Message, string Redirect)
{
ScriptManager.RegisterClientScriptBlock(this, base.GetType(), WebSqlHelper.Common.RndNum(8), "alert('" + Message + "');" + (string.IsNullOrEmpty(Redirect) ? "" : "location='" + Redirect + "';"), true);
}
}
}