📄 dispatch.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class outbound_Dispatch : System.Web.UI.Page
{
public enum SearchType
{
NotSet = -1,
Browser = 0,
Insert = 1
}
decimal priceTotal = 0; //本次发料金额总计
protected void Page_Load(object sender, EventArgs e)
{
Message.Text = "";
if (Session["DeliveryTable"] == null)
{
DataTable myTable = new DataTable();
myTable.Columns.Add(new DataColumn("DeliveryItemsID", typeof(string)));
myTable.Columns.Add(new DataColumn("DeliveryItemsName", typeof(string)));
myTable.Columns.Add(new DataColumn("DeliveryItemsSpecification", typeof(string)));
myTable.Columns.Add(new DataColumn("DeliveryItemsUnit", typeof(string)));
myTable.Columns.Add(new DataColumn("DeliveryItemsStandardPrice", typeof(decimal)));
myTable.Columns.Add(new DataColumn("DeliveryItemsInventory", typeof(decimal)));
myTable.Columns.Add(new DataColumn("DeliveryQuantity", typeof(decimal)));
myTable.Columns.Add(new DataColumn("DeliveryItemsMoney", typeof(decimal)));
myTable.Columns.Add(new DataColumn("DeliveryItemsLeftInventory", typeof(decimal)));
Session["DeliveryTable"] = myTable;
}
if (!IsPostBack)
{
radioBrowser.Checked = true;
TextBox DeliveryDateTextBox = FormView1.FindControl("DeliveryDateTextBox") as TextBox;
OboutInc.Calendar.Calendar Calendar1 = FormView1.FindControl("Calendar1") as OboutInc.Calendar.Calendar;
Calendar1.TextBoxId = DeliveryDateTextBox.ClientID;
SqlDataSource SqlDataSource2 = FormView1.FindControl("SqlDataSource2") as SqlDataSource;
SqlDataSource2.SelectParameters["UserName"].DefaultValue = this.User.Identity.Name;
}
//Response.Write(this.User.Identity.Name);
//Response.End();
}
/// <summary>
/// 删除Session中的DeliveryTable,避免在下一张小票中出现
/// 注意判断IsPostBack,否则每次PostBack都删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Unload(object sender, EventArgs e)
{
if (!IsPostBack && Session["DeliveryTable"] != null)
{
Session["DeliveryTable"] = null;
}
}
protected void radioButton_CheckedChanged(Object sender, System.EventArgs e)
{
if (radioBrowser.Checked)
{
MultiView1.ActiveViewIndex = (int)SearchType.Browser;
//InsertCancelButton_Click(radioBrowser,new EventArgs());
}
else if (radioInsert.Checked)
{
MultiView1.ActiveViewIndex = (int)SearchType.Insert;
}
}
protected void radioButtonDetails_CheckedChanged(Object sender, System.EventArgs e)
{
RadioButton radioBtn = (RadioButton)sender;
RadioButton radioBrowserDetails = radioBtn.Parent.FindControl("radioBrowserDetails") as RadioButton;
RadioButton radioInsertDetails = radioBtn.Parent.FindControl("radioInsertDetails") as RadioButton;
DropDownList DropDownList1 = FormView1.FindControl("DropDownList1") as DropDownList;
DropDownList DrpProjectCategory = FormView1.FindControl("DrpProjectCategory") as DropDownList;
DropDownList DrpUser = FormView1.FindControl("DrpUser") as DropDownList;
if (DropDownList1.Items.Count == 0)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csname = "PopupScript";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('没有您管理下的仓库,您没有权限发放物资。');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
radioInsertDetails.Checked = false;
radioBrowserDetails.Checked = true;
return;
}
if (DrpUser.Items.Count==0)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csname = "PopupScript";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('没有选择领料人。');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
radioInsertDetails.Checked = false;
radioBrowserDetails.Checked = true;
return;
}
if (DrpProjectCategory.Items.Count == 0)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csname = "PopupScript";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('没有生产项目。');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
radioInsertDetails.Checked = false;
radioBrowserDetails.Checked = true;
return;
}
int ProjectCategoryID = Convert.ToInt32(DrpProjectCategory.SelectedValue);
//是否有子节点?
if (IsNode(ProjectCategoryID))
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csname = "PopupScript";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('请选择一个具体的生产项目。');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
radioInsertDetails.Checked = false;
radioBrowserDetails.Checked = true;
return;
}
HtmlTableRow trList = radioBtn.Parent.Parent.FindControl("trList") as HtmlTableRow;
HtmlTableRow TrNew = radioBtn.Parent.Parent.FindControl("TrNew") as HtmlTableRow;
if (radioBrowserDetails.Checked)
{
GridView myGridView = (GridView)trList.FindControl("GridView1");
GetDeliveryItems(myGridView);
trList.Visible = true;
TrNew.Visible = false;
}
else if (radioInsertDetails.Checked)
{
trList.Visible = false;
GridView myGridView = (GridView)TrNew.FindControl("GridView2");
GetWarehouseItems(myGridView);
TrNew.Visible = true;
//一旦点击“新增”按钮,“仓库”下拉列表马上锁定,以防止用户先用某一仓库添加了
//一些记录,然后换成其他仓库继续添加,导致错误数据产生。同理,其他公共数据也锁定。
((TextBox)TrNew.Parent.FindControl("DeliveryDateTextBox")).Enabled = false;
((OboutInc.Calendar.Calendar)TrNew.Parent.FindControl("Calendar1")).DatePickerButtonText = "";
//((TextBox)TrNew.Parent.FindControl("DeliveryIDTextBox")).Enabled = false;
((DropDownList)TrNew.Parent.FindControl("DrpProjectCategory")).Enabled = false;
((DropDownList)TrNew.Parent.FindControl("DropDownList1")).Enabled = false;
((DropDownList)TrNew.Parent.FindControl("DropDownList2")).Enabled = false;
((DropDownList)TrNew.Parent.FindControl("DrpUser")).Enabled = false;
((LinkButton)FormView1.FindControl("InsertButton")).Enabled = true;
((TextBox)FormView1.FindControl("ItemIDTextBox")).Enabled = true;
((LinkButton)FormView1.FindControl("LinkButtonSearch")).Enabled = true;
}
}
private bool IsNode(int ProjectCategoryID)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlProviderConnection"].ConnectionString);
string strQuery = "Select ProjectCategoryID FROM ProjectCategories WHERE ParentID =" + ProjectCategoryID;
SqlCommand command = new SqlCommand(strQuery, con);
con.Open();
SqlDataReader reader = command.ExecuteReader();
return reader.HasRows;
}
/// <summary>
/// 取消之前先清空Session的DeliveryTable表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void InsertCancelButton_Click(object sender, EventArgs e)
{
if (Session["DeliveryTable"] != null)
{
Session["DeliveryTable"] = null;
}
//Response.Redirect("Delivery.aspx");
//可以保存以前的状态
((TextBox)FormView1.FindControl("DeliveryDateTextBox")).Enabled = true;
((OboutInc.Calendar.Calendar)FormView1.FindControl("Calendar1")).DatePickerButtonText = "<img src=\"../images/calendar.gif\"/>";
((DropDownList)FormView1.FindControl("DrpProjectCategory")).Enabled = true;
((DropDownList)FormView1.FindControl("DropDownList1")).Enabled = true;
((DropDownList)FormView1.FindControl("DropDownList2")).Enabled = true;
((DropDownList)FormView1.FindControl("DrpUser")).Enabled = true;
((LinkButton)FormView1.FindControl("InsertButton")).Enabled = false;
((TextBox)FormView1.FindControl("ItemIDTextBox")).Enabled = false;
((LinkButton)FormView1.FindControl("LinkButtonSearch")).Enabled = false;
RadioButton radioBrowserDetails = FormView1.FindControl("radioBrowserDetails") as RadioButton;
RadioButton radioInsertDetails = FormView1.FindControl("radioInsertDetails") as RadioButton;
radioBrowserDetails.Checked = true;
radioInsertDetails.Checked = false;
radioButtonDetails_CheckedChanged(radioBrowserDetails, new EventArgs());
((GridView)FormView1.FindControl("GridView1")).DataBind();
}
protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{
TextBox DeliveryDateTextBox = FormView1.FindControl("DeliveryDateTextBox") as TextBox;
DateTime DeliveryDate;
try
{
DeliveryDate = DateTime.Parse(DeliveryDateTextBox.Text);
}
catch (System.FormatException eFormat)
{
DeliveryDate = DateTime.Now;
}
SqlDataSource1.InsertParameters["DeliveryDate"].DefaultValue = DeliveryDate.ToShortDateString();
DropDownList drpProjectCategory = FormView1.FindControl("DrpProjectCategory") as DropDownList;
DropDownList drpWareHouseID = FormView1.FindControl("DropDownList1") as DropDownList;
DropDownList drpDepartmentID = FormView1.FindControl("DropDownList2") as DropDownList;
DropDownList DrpReceiverName = FormView1.FindControl("DrpUser") as DropDownList;
TextBox DescriptionTextBox = FormView1.FindControl("DescriptionTextBox") as TextBox;
SqlDataSource1.InsertParameters["ProjectCategoryID"].DefaultValue = drpProjectCategory.SelectedValue;
SqlDataSource1.InsertParameters["WareHouseID"].DefaultValue = drpWareHouseID.SelectedValue;
SqlDataSource1.InsertParameters["UserName"].DefaultValue = this.User.Identity.Name;
SqlDataSource1.InsertParameters["Description"].DefaultValue = DescriptionTextBox.Text;
SqlDataSource1.InsertParameters["DepartmentID"].DefaultValue = drpDepartmentID.SelectedValue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -