📄 dispatch.aspx.cs
字号:
}
Session["DeliveryTable"] = myTable;
GetDeliveryItems(myGridView);
myGridView.EditIndex = -1;
myGridView.DataBind();
Page.SetFocus((TextBox)FormView1.FindControl("ItemIDTextBox"));
}
/// <summary>
/// 设置格式,更主要的是金额合计并验证是否超出定额
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// add the UnitPrice to the running total variables
for (int i=5;i<12;i++)
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
priceTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "DeliveryItemsMoney"));
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[7].Text = "金额总计:";
// for the Footer, display the running totals
e.Row.Cells[8].Text = priceTotal.ToString("c");
e.Row.Cells[8].HorizontalAlign = HorizontalAlign.Right;
e.Row.Font.Bold = true;
priceTotal = 0;
}
}
/// <summary>
/// 对于库存量为0的物料给予警告:颜色为黄色。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// determine the value of the UnitsInStock field
decimal unitsInStock = Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Quantity"));
if (unitsInStock == 0)
// color the background of the row yellow
e.Row.BackColor = System.Drawing.Color.Yellow;
if (unitsInStock < 0)
// color the background of the row yellow
e.Row.BackColor = System.Drawing.Color.LightPink;
}
}
/// <summary>
/// 选中物资记录,添加该记录,暂时将发料数量设为0,切换到浏览页面,默认编辑模式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
GridView myGridView = (GridView)sender;
//AddDelivery(myGridView.SelectedValue.ToString());
AddDelivery(myGridView.SelectedRow);
myGridView.SelectedIndex = -1;
RadioButton radioBrowserDetails = myGridView.Parent.Parent.FindControl("radioBrowserDetails") as RadioButton;
RadioButton radioInsertDetails = myGridView.Parent.Parent.FindControl("radioInsertDetails") as RadioButton;
radioBrowserDetails.Checked = true;
radioInsertDetails.Checked = false;
radioButtonDetails_CheckedChanged(radioBrowserDetails, new EventArgs());
//列表GridView
GridView myGridView1 = myGridView.Parent.Parent.FindControl("GridView1") as GridView;
//myGridView1.PageIndex = myGridView1.PageCount - 1;
//myGridView1.EditIndex = myGridView1.Rows.Count - 1;
myGridView1.EditIndex = 0;
myGridView1.DataBind();
//光标
GridViewRow editRow = myGridView1.Rows[myGridView1.EditIndex];
Page.SetFocus((TextBox)editRow.FindControl("txtDeliveryItemsQuantity"));
}
/// <summary>
/// 用户在没有保存小票之前,详细发料信息暂时不写入数据库,
/// 先存在一DataTable中。
/// 等编辑完成保存的时候,
/// 用存储过程完成主从表记录的插入,以保证数据完整性和一致性
/// </summary>
/// <param name="ItemsID"></param>
private void AddDelivery(GridViewRow addItemsRow)
{
DataTable myTable = Session["DeliveryTable"] as DataTable;
DataRow dr = myTable.NewRow();
//DataRowView rowView = (DataRowView)addItemsRow.DataItem;
//nnd,第一列是“发料”链接。从第2列起算
dr[0] = addItemsRow.Cells[1].Text;
dr[1] = addItemsRow.Cells[2].Text;
dr[2] = addItemsRow.Cells[3].Text;
dr[3] = addItemsRow.Cells[4].Text;
dr[4] = Convert.ToDecimal(addItemsRow.Cells[5].Text);
dr[5] = Convert.ToDecimal(addItemsRow.Cells[6].Text);
/*string strScript = "";
strScript = "<script>";
strScript = strScript + "prompt('请输入实发数量:','0');";
strScript = strScript + "</script>";
Response.Write(strScript);*/
//dr[6] = 0;
dr[7] = 0;
//剩余库存暂时等于初始库存
dr[8] = dr[5];
myTable.Rows.InsertAt(dr, 0);
Session["DeliveryTable"] = myTable;
}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView myGridView = (GridView)sender;
GetWarehouseItems(myGridView);
myGridView.PageIndex = e.NewPageIndex;
myGridView.DataBind();
}
protected void LinkButtonSearch_Click(object sender, EventArgs e)
{
RadioButton radioInsertDetails = FormView1.FindControl("radioInsertDetails") as RadioButton;
RadioButton radioBrowserDetails = FormView1.FindControl("radioBrowserDetails") as RadioButton;
radioBrowserDetails.Checked = false;
radioInsertDetails.Checked = true;
radioButtonDetails_CheckedChanged(radioInsertDetails, new EventArgs());
}
/// <summary>
/// 根据当日车辆和生产定额,显示在发料明细表中
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAuto_Click(object sender, EventArgs e)
{
DropDownList DrpProjectCategory = FormView1.FindControl("DrpProjectCategory") as DropDownList;
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 = "PopupScriptProject";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('请选择一个具体的生产项目。');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
return;
}
DropDownList DrpDepartmentID = FormView1.FindControl("DropDownList2") as DropDownList;
int DepartmentID = Convert.ToInt32(DrpDepartmentID.SelectedValue);
DropDownList DropDownList1 = FormView1.FindControl("DropDownList1") as DropDownList;
int WareHouseID = Convert.ToInt32(DropDownList1.SelectedValue);
TextBox DeliveryDateTextBox = FormView1.FindControl("DeliveryDateTextBox") as TextBox;
DateTime DeliveryDate;
try
{
DeliveryDate = DateTime.Parse(DeliveryDateTextBox.Text);
}
catch (System.FormatException eFormat)
{
DeliveryDate = DateTime.Now;
}
DataTable myTable = Session["DeliveryTable"] as DataTable;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySqlProviderConnection"].ConnectionString);
string strQuery = "SELECT Quantity From RepairDetail Where [RepairDetail].RepairID in (Select [RepairMain].RepairID From RepairMain Where RepairDate='"
+ DeliveryDate.ToShortDateString() + "')" +
" AND ProjectCategoryID=" + ProjectCategoryID;
SqlCommand command = new SqlCommand(strQuery, con);
con.Open();
SqlDataReader reader = command.ExecuteReader();
//首先判断是否当天该项目有生产记录
if (!reader.HasRows)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csname = "PopupScriptNoProject";
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname))
{
String cstext = "alert('该日没有制定生产记录或者生产记录中没有该项目!');";
cs.RegisterStartupScript(cstype, csname, cstext, true);
}
con.Close();
return;
}
else
{
con.Close();
}
strQuery = "Select * From dbo.GetDeliveryRatioByCategoryID(" + ProjectCategoryID + "," + DepartmentID + "," + WareHouseID + ",'" + DeliveryDate.ToShortDateString() + "')";
command = new SqlCommand(strQuery, con);
con.Open();
reader = command.ExecuteReader();
try
{
while (reader.Read())
{
DataRow dr = myTable.NewRow();
for (int i = 0; i < 7; i++)
{
dr[i] = reader[i];
}
dr[7] = Convert.ToDecimal(dr[4]) * Convert.ToDecimal(dr[6]);
//dr[7] = 0;
dr[8] = Convert.ToInt32(dr[5]) - Convert.ToDecimal(dr[6]);
//dr[8] = 0;
myTable.Rows.InsertAt(dr, 0);
}
}
finally
{
reader.Close();
}
Session["DeliveryTable"] = myTable;
GetDeliveryItems((GridView)FormView1.FindControl("GridView1"));
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());
}
private void GetDeliveryItems(GridView myGridView)
{
DataTable myTable = Session["DeliveryTable"] as DataTable;
myGridView.DataSource = myTable;
myGridView.DataBind();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -