/*
*************************************************************************
* Page/Class Name : BlackCleanPeopleQty.cs
* Title : 黑料-洗净包装作业人数维护
* @author : Garry
* Create Date : 2012/04/16
* Last Modifier :
* Last Modify Date :
* TABLE :
*************************************************************************
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Genesis.Gtimes.ADM;
using Genesis.Gtimes.Common;
using Genesis.Gtimes.UserControl;
using Genesis.Gtimes.WIP;
using Genesis.Gtimes.Transaction;
using Genesis.Gtimes.Transaction.WIP;
using System.Data;
using Genesis.Gtimes.Transaction.EQP;
using System.Text;
namespace Genesis.Gtimes.GeniusXM.GeniusXM.Genius_Carrier
{
public partial class BlackCleanPeopleQty : PageBase
{
#region Property
/// <summary>
/// Grid中的绑定数据
/// </summary>
private DataTable dtItem
{
get
{
return (DataTable)this["BlackCleanPeopleQty"];
}
set { this["BlackCleanPeopleQty"] = value; }
}
#endregion
#region Page_Load
/// <summary>
/// 页面加载,初始化页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
//檢查使用者權限與閒置時間.
CheckRightAndTimeOut();
if (!IsPostBack)
{
//初始化页面
InitializeControl();
//清除页面数据
ClearAll();
//绑定CARRIER黑料品名到下拉选单
BindingPartNo();
}
}
#endregion
#region Init Event
//清除界面显示.
private void ClearAll()
{
//页面UserControl按钮控制
SetSequenceControlBar1.AddButton.Visible = false;
SetSequenceControlBar1.AddParamButton.Visible = false;
SetSequenceControlBar1.EditButton.Visible = false;
SetSequenceControlBar1.EnableButton.Visible = false;
SetSequenceControlBar1.DisableButton.Visible = false;
SetSequenceControlBar1.DeleteButton.Visible = false;
//清除各控件信息
ddlPartNo.SelectedIndex = -1;
gvData.EditIndex = -1;
gvData.DataSource = null;
gvData.DataBind();
this.SetSequenceControlBar1.AddParamButtonEnable = false;
this.SetSequenceControlBar1.SaveButtonEnable = false;
}
/// <summary>
/// 事件绑定,绑定方法到页面的按钮
/// </summary>
/// <param name="e"></param>
protected override void OnInit(EventArgs e)
{
//新增一条订单信息方法绑定
//this.SetSequenceControlBar1.AddParamButton.Click += new ImageClickEventHandler(AddParamButton_Click);
//保存订单信息方法绑定
this.SetSequenceControlBar1.SaveButton.Click += new ImageClickEventHandler(SaveButton_Click);
//清除页面方法绑定
this.SetSequenceControlBar1.ExitButton.Click += new ImageClickEventHandler(ExitButton_Click);
base.OnInit(e);
}
/// <summary>
/// 初始化方法,获取程式标题
/// </summary>
private void InitializeControl()
{
//获取当前程序中文显示
FunctionListUtility.FunctionListFunction oPGFun = new FunctionListUtility.FunctionListFunction(this.DBC);
SetSequenceControlBar1.FunctionTitleText = oPGFun.GetFunctionName((string)Session["Lang"], this.Page.Request.AppRelativeCurrentExecutionFilePath.Substring(1));
}
/// <summary>
/// 离开按钮的绑定方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void ExitButton_Click(object sender, ImageClickEventArgs e)
{
try
{
//初始化页面
InitializeControl();
//清除页面数据
ClearAll();
//绑定CARRIER黑料品名到下拉选单
BindingPartNo();
//页面加载时带出所有黑料品名对应的信息
//ShowAllPartNoPeopleSet();
}
catch (Exception ex)
{
WriteClientMessage(this.Page, MessageType.Exception, ex.Message);
}
}
//绑定CARRIER黑料品名到下拉选单 --OK
private void BindingPartNo()
{
ddlPartNo.Items.Clear();
string sql = @"SELECT DISTINCT T.PARTNO FROM PF_PARTNO t WHERE T.PARTNO_TYPE_SID='GTI11062410501207136' AND T.PARTNO LIKE 'WC%'";
sql = DBC.GetCommandText(sql, SQLStringType.OracleSQLString);
DataTable dtPartNo = DBC.Select(sql);
if (dtPartNo != null && dtPartNo.Rows.Count > 0)
{
//遍历将Carrier黑料品名添加到下拉选单
for (int i = 0; i < dtPartNo.Rows.Count; i++)
{
ddlPartNo.Items.Add(dtPartNo.Rows[i]["PARTNO"].ToString());
}
ddlPartNo.Items.Insert(0, " ");
}
else
{
throw new Exception("无法取得CARRIER黑料品名");
}
}
#endregion
#region TextBox Event
/// <summary>
/// 选定某一黑料品名时,取得该黑料品名的信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPartNo_TextChanged(object sender, EventArgs e)
{
try
{
gvData.Columns.Clear();
gvData.DataSource = null;
//依黑料品名,获得所有模号和穴数
string sql = string.Format("SELECT PARTNO LOT,MOULD_TYPE MOULD,MOULD_NUM CAVE FROM ZZ_MOULD WHERE PARTNO='{0}' order by mould_type", ddlPartNo.SelectedItem.Text);
DataTable dtAll = this.DBC.Select(sql);
//依黑料品名得到最大的穴数,为了自动生成GRIDVIEW栏位
string maxCaveSql = string.Format("SELECT MAX(MOULD_NUM) MAXCAVE FROM ZZ_MOULD WHERE PARTNO='{0}'", ddlPartNo.SelectedItem.Text);
DataTable dtMaxCave = this.DBC.Select(maxCaveSql);
//当表内有数据时,查询数据为行转列做准备
string[] columnName = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" };
StringBuilder sbCase = new StringBuilder();
StringBuilder sbSum = new StringBuilder();
for (int s = 1; s <= Convert.ToInt32(dtMaxCave.Rows[0][0].ToString()); s++)
{
if (s != Convert.ToInt32(dtMaxCave.Rows[0][0].ToString()))
{
sbCase.Append(string.Format(@" (CASE WHEN CAVE='{0}' THEN QUANTITY END) {1}, ", s.ToString(), columnName[s - 1]));
sbSum.Append(string.Format(@" SUM({0}){0}, ", columnName[s - 1]));
}
else
{
sbCase.Append(string.Format(@" (CASE WHEN CAVE='{0}' THEN QUANTITY END) {1} ", s.ToString(), columnName[s - 1]));
sbSum.Append(string.Format(@" SUM({0}){0} ", columnName[s - 1]));
}
}
//查询表内是否有数据,有数据就带出
string sqlData = string.Format(@" SELECT LOT,MOULD,CAVE,
{1}
FROM(
SELECT LOT,MOULD,CAVEQTY CAVE,
{2}
FROM ZZ_BLACK_CLEAN_PEOPLE_QTY WHERE LOT='{0}')
GROUP BY LOT,MOULD,CAVE
ORDER BY MOULD", ddlPartNo.SelectedItem.Text, sbSum.ToString(), sbCase.ToString());
dtItem = this.DBC.Select(sqlData);
//生成GRIDVIEW列
BoundField bfLot = new BoundField();
bfLot.SortExpression = "lot";
bfLot.DataField = "lot";
bfLot.HeaderText = "黑料品名";
gvData.Columns.Add(bfLot);
BoundField bfMould = new BoundField();
bfMould.SortExpression = "mould";
bfMould.DataField = "mould";
bfMould.HeaderText = "模号";
gvData.Columns.Add(bfMould);
BoundField bfCave = new BoundField();
bfCave.SortExpression = "cave";
bfCave.DataField = "cave";
bfCave.HeaderText = "穴数";
gvData.Columns.Add(bfCave);
//依品名最大穴号,生成文本框
for (int i = 0; i < Convert.ToInt32(dtMaxCave.Rows[0][0].ToString()); i++)
{
string sDataFile = "";
TemplateField tfP = new TemplateField();
tfP.HeaderText = (i + 1).ToString();
tfP.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, i.ToString(), true);
tfP.SortExpression = "txt" + (i + 1).ToString();
gvData.Columns.Add(tfP);
dtAll.Columns.Add((i + 1).ToString());
}
//如果数据库内无数据则生成空的数据,否则取值后赋值
if (dtItem == null)
{
gvData.DataSource = dtAll;
gvData.DataBind();
SetSequenceControlBar1.SaveButtonEnable = true;
}
else
{
gvData.DataSource = dtItem;
gvData.DataBind();
SetSequenceControlBar1.SaveButtonEnable = true;
}
}
catch (Exception ex)
{
//顯示錯誤訊息
WriteClientMessage(this.Page, MessageType.Exception, ex.Message);
}
}
#endregion
#region Buttom Event
/// <summary>
/// 确定保存的绑定方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SaveButton_Click(object sender, ImageClickEventArgs e)
{
try
{
List<IDbCommand> commands = new List<IDbCommand>();
//如果表内无数据,插入数据,否则更新数据
if (dtItem == null)
{
for (int i = 0; i < gvData.Rows.Count; i++)
{
for (int j = 3; j < gvData.Columns.Count; j++)
{
if (gvData.Rows[i].Cells[j].Text == "无")
continue;
TextBox txtQty = (TextBox)gvData.Rows[i].FindControl("txt" + (j - 2).ToString());
//SELECT ZZ_BLACK_CLEAN_PEOPLE_QTY_SID,LOT,MOULD,CAVE,QUANTITY,CREATE_DATE,CREATE_USER,UPDATE_DATE,UPDATE_USER FROM ZZ_BLACK_CLEAN_PEOPLE_QTY
InsertCommandBuilder insertEDC = new InsertCommandBuilder(DBC, "ZZ_BLACK_CLEAN_PEOPLE_QTY");
insertEDC.InsertColumn("ZZ_BLACK_CLEAN_PEOPLE_QTY_SID", DBC.GetSID());
insertEDC.InsertColumn("LOT", gvData.Rows[i].Cells[0].Text);
insertEDC.InsertColumn("MOULD", gvData.Rows[i].Cells[1].Text);
insertEDC.InsertColumn("CAVEQTY", gvData.Rows[i].Cells[2].Text);
insertEDC.InsertColumn("CAVE", gvData.Columns[j].HeaderText);
insertEDC.InsertColumn("QUANTITY", txtQty.Text);
insertEDC.InsertColumn("CREATE_DATE", this.DBC.GetDBTime());
insertEDC.InsertColumn("CREATE_USER", this.User.Identity.Name);
insertEDC.InsertColumn("UPDATE_DATE", this.DBC.GetDBTime());
insertEDC.InsertColumn("UPDATE_USER", this.User.Identity.Name);
commands.AddRange(insertEDC.GetCommands());
}
}
this.DBC.DoTransaction(commands);
// ClearAll();
WriteClientMessage(this.Page, MessageType.Normal, "黑料-洗净包装作业人数维护成功");
this.SetSequenceControlBar1.SaveButtonEnable = false;
}
else
{
for (int i = 0; i < gvData.Rows.Count; i++)
{
for (int j = 3; j < gvData.Columns.Count; j++)
{
if (gvData.Rows[i].Cells[j].Text == "无")
continue;
TextBox txtQty = (TextBox)gvData.Rows[i].FindControl("txt" + (j - 2).ToString());
//确认是否有更改,有更改就更新
if (dtItem.Rows[i][j].ToString() == txtQty.Text.ToString())
continue;
UpdateCommandBuilder update = new UpdateCommandBuilder(DBC, "ZZ_BLACK_CLEAN_PEOPLE_QTY");
update.UpdateColumn("QUANTITY", txtQty.Text);
update.UpdateColumn("UPDATE_DATE", this.DBC.GetDBTime());
update.UpdateColumn("UPDATE_USER", this.User.Identity.Name);
update.WhereAnd("LOT", gvData.Rows[i].Cells[0].Text);
update.WhereAnd("MOULD", gvData.Rows[i].Cells[1].Text);
update.WhereAnd("CAVE", gvData.Columns[j].HeaderText);
update.DoTransaction();
}
}
WriteClientMessage(this.Page, MessageType.Normal, "黑料-洗净包装作业人数更新成功");
this.SetSequenceControlBar1.SaveButtonEnable = false;
}
}
catch (Exception ex)
{
WriteClientMessage(this.Page, MessageType.Exception, ex.Message);
}
}
#endregion
#region GridView Event
int i = 0;//若表内有数据赋值,行号变化
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//若品名不同模号有不同穴数,没有的穴数显示无且不可编辑
int cave = Convert.ToInt32(e.Row.Cells[2].Text);
for (int i = (3 + cave); i < gvData.Columns.Count; i++)
{
e.Row.Cells[i].Enabled = false;
e.Row.Cells[i].Text = "无";
}
//有数据赋值
if (dtItem != null)
{
for (int j = 3; j < dtItem.Columns.Count; j++)
{
if (e.Row.Cells[j].Text == "无")
continue;
TextBox txtQty = (TextBox)e.Row.FindControl("txt" + (j - 2).ToString());
txtQty.Text = dtItem.Rows[i][j].ToString();
}
}
i++;
}
}
//绑定数据库前生成文本框
protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
for (int i = 3; i < gvData.Columns.Count; i++)
{
TextBox txtSpec = new TextBox();
txtSpec.ID = "txt" + (i - 2).ToString();
txtSpec.Width = Unit.Pixel(60);
txtSpec.TextMode = TextBoxMode.SingleLine;
txtSpec.Font.Size = 14;
txtSpec.Height = Unit.Pixel(20);
txtSpec.Text = "";
txtSpec.ToolTip = txtSpec.Text;
e.Row.Cells[i].Controls.Clear();
e.Row.Cells[i].Controls.Add(txtSpec);
}
break;
}
}
#region 动态生成GRIDVIEW 类
/// <summary>
/// GridViewTemplate
/// </summary>
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private string columnName;
private bool DisplaySubTitle = false;
public GridViewTemplate(DataControlRowType type, string colname, bool subtitle)
{
templateType = type;
columnName = colname;
DisplaySubTitle = subtitle;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
break;
case DataControlRowType.DataRow:
break;
default:
break;
}
}
}
#endregion
#endregion
}
}