123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- using DevExpress.XtraPrinting.Export.Pdf;
- using HslCommunication.Profinet.Knx;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using NPOI.HSSF.UserModel;
- using NPOI.SS.UserModel;
- using NPOI.SS.Formula.Functions;
- namespace UAS_MES_NEW.Special
- {
- public partial class Special_Reset : Form
- {
- DataHelper dh;
- LogStringBuilder sql = new LogStringBuilder();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataTable Dbfind;
- DataTable dt;
- List<String> sb = new List<string>();
- public Special_Reset()
- {
- InitializeComponent();
- }
- private void Special_BoxSplit_Load(object sender, EventArgs e)
- {
- dh = SystemInf.dh;
- asc.controllInitializeSize(this);
- cd_stepcode.FormName = Name;
- cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id";
- cd_stepcode.SetValueField = new string[] { "cd_stepcode", "cd_stepno" };
- cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序";
- cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
- cd_stepcode.DBTitle = "回流工序";
- cd_stepcode.DbChange += Cd_stepcode_DbChange;
- }
- private void Cd_stepcode_DbChange(object sender, EventArgs e)
- {
- Dbfind = cd_stepcode.ReturnData;
- BaseUtil.SetFormValue(this.Controls, Dbfind);
- }
- private bool ReSN(string sncode, string stepcode)
- {
- DataTable dt = (DataTable)dh.ExecuteSql("select ms_paststep,ms_makecode from makeserial where ms_sncode ='" + sncode + "' order by ms_id desc", "select");
- if (!dt.Rows[0]["ms_paststep"].ToString().Contains(cd_stepcode.Text))
- {
- OperatResult.AppendText(">>序列号" + sncode + "不允许回流到未执行工序\n", Color.Red);
- return false;
- }
- string makecode = dt.Rows[0]["ms_makecode"].ToString();
- string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + stepcode + "'").ToString();
- dh.ExecuteSql("update makeserial set ms_status=1,ms_outboxcode='',ms_printcount = 0, ms_nextstepcode= '" + stepcode + "' where ms_sncode='" + sncode + "' and ms_makecode='" + makecode + "'", "update");
- dh.ExecuteSql("delete makebad where mb_sncode = '" + sncode + "' and mb_makecode='" + makecode + "' and mb_status = 0", "delete");
- dh.ExecuteSql("delete labelprintlog where lpl_value = '" + sncode + "' ", "delete");
- sql.Clear();
- sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',");
- sql.Append("cm_dropdate =sysdate,CM_REMARK = '重置站点拆解',cm_dropstep='" + User.CurrentStepCode + "',");
- sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_sncode = '" + sncode + "' and cm_makecode='" + makecode + "' and cm_stepcode in (select cd_stepcode from craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id where ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_detno >=" + cd_stepno.Text + " )");
- dh.ExecuteSql(sql.GetString(), "update");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sncode, "");
- return true;
- }
- private void Split_Click(object sender, EventArgs e)
- {
- if (sb.Count == 0 || cd_stepcode.Text == "")
- {
- OperatResult.AppendText(">>采集数与回流工位不能为空\n", Color.Red);
- return;
- }
- string Delete = MessageBox.Show(this.ParentForm, "是否确认重置站点?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (Delete == "Yes")
- {
- if (serBtn.Checked)
- {
- for (int i = 0; i < sb.Count; i++)
- {
- if (ReSN(sb[i].ToString(), cd_stepcode.Text))
- OperatResult.AppendText("SN:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
- }
- WeighRecord.Clear();
- sb.Clear();
- }
- else if (bigboxBtn.Checked)
- {
- string stname = dh.getFieldDataByCondition("step", "st_name", "st_code = '" + cd_stepcode.Text + "'").ToString();
- for (int i = 0; i < sb.Count; i++)
- {
- DataTable dt2 = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_outboxcode = '" + sb[i].ToString() + "'", "select");
- for (int k = 0; k < dt2.Rows.Count; k++)
- {
- ReSN(dt2.Rows[k]["ms_sncode"].ToString(), cd_stepcode.Text);
- }
- dh.ExecuteSql("delete from labelprintlog where lpl_value='" + sb[i].ToString() + "'", "delete");
- dh.ExecuteSql("insert into PACKAGEBACKUP(PA_ID, PA_PRODCODE, PA_OUTBOXCODE, PA_PACKDATE, PA_LEVEL, PA_PACKAGEQTY, PA_TOTALQTY, PA_MAKECODE, PA_STATUS, PA_INDATE, PA_SALECODE, PA_PRINTCOUNT, PA_CUSTCODE, PA_TYPE, PA_WEIGHT, PA_CURRENTQTY, PA_PACKTYPE, PA_CHECKNO, PA_DOWNSTATUS, PA_STANDARDQTY, PA_SCCODE, PA_YMD, PA_MOTHERCODE, PA_CURRENTSTEP, PA_NEXTSTEP, PA_OUTNO, PA_IOSTATUS, PA_REMARK, PA_WHCODE, PA_B2BID, PA_INNO)" +
- " select PA_ID, PA_PRODCODE, PA_OUTBOXCODE, PA_PACKDATE, PA_LEVEL, PA_PACKAGEQTY, PA_TOTALQTY, PA_MAKECODE, PA_STATUS, PA_INDATE, PA_SALECODE, PA_PRINTCOUNT, PA_CUSTCODE, PA_TYPE, PA_WEIGHT, PA_CURRENTQTY, PA_PACKTYPE, PA_CHECKNO, PA_DOWNSTATUS, PA_STANDARDQTY, PA_SCCODE, PA_YMD, PA_MOTHERCODE, PA_CURRENTSTEP, PA_NEXTSTEP, PA_OUTNO, PA_IOSTATUS, PA_REMARK, PA_WHCODE, PA_B2BID, PA_INNO from package where pa_outboxcode='" + sb[i].ToString() + "'", "insert");
- dh.ExecuteSql("insert into PACKAGEBACKUPDETAIL select * from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "insert");
- dh.ExecuteSql("delete from package where pa_outboxcode = '" + sb[i].ToString() + "'", "delete");
- //删除箱的明细
- dh.ExecuteSql("delete from packagedetail where pd_outboxcode='" + sb[i].ToString() + "'", "delete");
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "站点重置", "站点重置至" + stname, sb[i].ToString(), "");
- OperatResult.AppendText("卡通箱:" + sb[i].ToString() + "回流至" + cd_stepcode.Text + "完成\n", Color.Green);
- }
- WeighRecord.Clear();
- sb.Clear();
- }
- sql.Clear();
- sql.Append("MERGE INTO makecraftdetail USING (select mcd_macode,mcd_detno,mcd_stepcode,mcd_stepname,nvl(count(distinct A.ms_sncode),0) n,nvl(count(distinct B.ms_sncode),0) bn,(select nvl(count(distinct sp_sncode),0) from STEPPASSED where SP_MAKECODE = mcd_macode AND SP_STEPCODE = mcd_stepcode) inqty from MAKECRAFTdetail");
- sql.Append(" left join makeserial A on mcd_macode = A.ms_makecode and mcd_stepcode = A.ms_nextstepcode AND A.MS_STATUS = 1 LEFT JOIN MAKESERIAL B ON mcd_macode = B.ms_makecode AND MCD_STEPCODE = B.MS_STEPCODE AND B.MS_STATUS = 3 where mcd_macode = '" + ms_makecode.Text + "' group by mcd_macode,mcd_detno, mcd_stepcode, mcd_stepname order by mcd_detno asc) A");
- sql.Append(" ON (makecraftdetail.MCD_MACODE = A.MCD_MACODE and makecraftdetail.mcd_stepcode = A.mcd_stepcode) ");
- sql.Append(" WHEN MATCHED THEN UPDATE SET makecraftdetail.mcd_inqty = A.inqty,makecraftdetail.mcd_outqty = A.inqty,makecraftdetail.mcd_okqty = A.inqty ");
- dh.ExecuteSql(sql.GetString(), "update");
- }
- }
- private void bigboxBtn_Click(object sender, EventArgs e)
- {
- if (((RadioButton)sender).Checked == true)
- {
- if (WeighRecord.Items.Count > 0)
- {
- string logout_confirm = MessageBox.Show(this.ParentForm, "是否更换采集项(已录入信息会清空)?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (logout_confirm == "Yes")
- {
- WeighRecord.Items.Clear();
- sb.Clear();
- ms_makecode.Text = "";
- ms_prodcode.Text = "";
- cr_code.Text = "";
- cd_stepcode.Text = "";
- }
- else
- {
- serBtn.Checked = bigboxBtn.Checked;
- bigboxBtn.Checked = !serBtn.Checked;
- }
- }
- if (((RadioButton)sender).Name == "serBtn")
- {
- input.Focus();
- OperatResult.AppendText("请输入序列号进行采集\n", Color.Black, input);
- }
- else if (((RadioButton)sender).Name == "bigboxBtn")
- {
- input.Focus();
- OperatResult.AppendText("请输入箱号进行采集\n", Color.Black, input);
- }
- }
- }
- private void cr_code_TextChanged(object sender, EventArgs e)
- {
- cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
- }
- private void input_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (serBtn.Checked)
- {
- dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei1='" + input.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- input.Text = dt.Rows[0]["ms_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select ms_sncode from makeserial where ms_imei2='" + input.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- input.Text = dt.Rows[0]["ms_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei1='" + input.Text + "' order by mil_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- input.Text = dt.Rows[0]["mil_sncode"].ToString();
- }
- else
- {
- dt = (DataTable)dh.ExecuteSql("select mil_sncode from makeimeilist where mil_imei2='" + input.Text + "' order by mil_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- input.Text = dt.Rows[0]["mil_sncode"].ToString();
- }
- }
- }
- }
- dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_prodcode,ms_sncode,ms_craftcode cr_code,ms_status,ms_outboxcode from makeserial where ms_sncode = '" + input.Text + "' or ms_imei1='" + input.Text + "' or ms_imei2='" + input.Text + "' order by ms_id desc", "select");
- if (dt.Rows.Count > 0)
- {
- input.Text = dt.Rows[0]["ms_sncode"].ToString();
- if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
- {
- OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
- return;
- }
- if (dt.Rows[0]["ms_status"].ToString() == "3")
- {
- OperatResult.AppendText("SN:" + input.Text + "为不良品,不允许采集\n", Color.Red, input);
- return;
- }
- if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
- {
- OperatResult.AppendText("SN:" + input.Text + "已装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + ",不允许采集\n", Color.Red, input);
- return;
- }
- BaseUtil.SetFormValue(this.Controls, dt);
- if (sb.Contains(dt.Rows[0]["ms_sncode"].ToString()))
- {
- OperatResult.AppendText("SN:" + input.Text + "已采集\n", Color.Red, input);
- return;
- }
- WeighRecord.Items.Add(dt.Rows[0]["ms_sncode"].ToString());
- sb.Add(dt.Rows[0]["ms_sncode"].ToString());
- OperatResult.AppendText("SN:" + input.Text + "采集\n", Color.Green, input);
- cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
- }
- else
- {
- OperatResult.AppendText("SN:" + input.Text + "不存在\n", Color.Red, input);
- return;
- }
- }
- else if (bigboxBtn.Checked)
- {
- dt = (DataTable)dh.ExecuteSql("select pa_makecode ms_makecode,pa_prodcode ms_prodcode,pa_outboxcode,pa_mothercode,ma_craftcode,nvl(pa_iostatus,0)pa_iostatus,ma_craftcode cr_code from package left join make on pa_makecode = ma_code where pa_outboxcode = '" + input.Text + "' and pa_type = '1'", "select");
- if (dt.Rows.Count > 0)
- {
- if (ms_makecode.Text != "" && dt.Rows[0]["ms_makecode"].ToString() != ms_makecode.Text)
- {
- OperatResult.AppendText("SN:" + input.Text + "所属工单" + dt.Rows[0]["ms_makecode"].ToString() + "与当前工单" + ms_makecode.Text + "不一致\n", Color.Red, input);
- return;
- }
- if (dt.Rows[0]["pa_iostatus"].ToString() != "0")
- {
- OperatResult.AppendText("卡通箱:" + input.Text + "处于状态入库状态,不允许采集\n", Color.Red, input);
- return;
- }
- if (dt.Rows[0]["pa_mothercode"].ToString() != "")
- {
- OperatResult.AppendText("卡通箱:" + input.Text + "已装栈板" + dt.Rows[0]["pa_mothercode"].ToString() + ",不允许采集\n", Color.Red, input);
- return;
- }
- BaseUtil.SetFormValue(this.Controls, dt);
- if (sb.Contains(dt.Rows[0]["pa_outboxcode"].ToString()))
- {
- OperatResult.AppendText("卡通箱:" + input.Text + "已采集\n", Color.Red, input);
- return;
- }
- WeighRecord.Items.Add(dt.Rows[0]["pa_outboxcode"].ToString());
- sb.Add(dt.Rows[0]["pa_outboxcode"].ToString());
- OperatResult.AppendText("卡通箱:" + input.Text + "采集\n", Color.Green, input);
- cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
- }
- else
- {
- OperatResult.AppendText("卡通箱:" + input.Text + "不存在\n", Color.Red, input);
- return;
- }
- }
- }
- }
- private void 数据清空_Click(object sender, EventArgs e)
- {
- BaseUtil.CleanControls(this.Controls);
- WeighRecord.Items.Clear();
- sb.Clear();
- }
- private void Special_Reset_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Export_Click(object sender, EventArgs e)
- {
- ExportFileDialog.Description = "选择导出的路径";
- DialogResult result = ExportFileDialog.ShowDialog();
- if (result == DialogResult.OK)
- {
- ExcelHandler eh = new ExcelHandler();
- sql.Clear();
- sql.Append("select ''箱号,'' SN from dual ");
- dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- eh.ExportExcel(dt, ExportFileDialog.SelectedPath+"\\导出模板.xls");
- //string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- }
- }
- private void ImportExcel_Click(object sender, EventArgs e)
- {
- ImportExcel1.Filter = "(*.xls)|*.xls";
- DialogResult result;
- result = ImportExcel1.ShowDialog();
- if (result == DialogResult.OK)
- {
- DataTable dt = ExcelToDataTable(ImportExcel1.FileName, true);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (bigboxBtn.Checked)
- {
- input.Text= dt.Rows[i]["箱号"].ToString();
- input_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- }
- if (serBtn.Checked)
- {
- input.Text = dt.Rows[i]["SN"].ToString();
- input_KeyDown(sender, new KeyEventArgs(Keys.Enter));
- }
- }
- }
- }
- public static DataTable ExcelToDataTable(string filePath, bool isColumnName)
- {
- DataTable dataTable = null;
- FileStream fs = null;
- DataColumn column = null;
- DataRow dataRow = null;
- IWorkbook workbook = null;
- ISheet sheet = null;
- IRow row = null;
- ICell cell = null;
- int startRow = 0;
- try
- {
- using (fs = File.OpenRead(filePath))
- {
- // 2007版本
- workbook = new HSSFWorkbook(fs);
- if (workbook != null)
- {
- sheet = workbook.GetSheetAt(0);//读取第一个sheet,当然也可以循环读取每个sheet
- dataTable = new DataTable();
- if (sheet != null)
- {
- int rowCount = sheet.LastRowNum;//总行数
- if (rowCount > 0)
- {
- IRow firstRow = sheet.GetRow(0);//第一行
- int cellCount = firstRow.LastCellNum;//列数
- //构建datatable的列
- if (isColumnName)
- {
- startRow = 1;//如果第一行是列名,则从第二行开始读取
- for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
- {
- cell = firstRow.GetCell(i);
- if (cell != null)
- {
- if (cell.StringCellValue != null)
- {
- column = new DataColumn(cell.StringCellValue);
- dataTable.Columns.Add(column);
- }
- }
- }
- }
- else
- {
- for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
- {
- column = new DataColumn("column" + (i + 1));
- dataTable.Columns.Add(column);
- }
- }
- //填充行
- for (int i = startRow; i <= rowCount; ++i)
- {
- row = sheet.GetRow(i);
- if (row == null) continue;
- dataRow = dataTable.NewRow();
- for (int j = row.FirstCellNum; j < cellCount; ++j)
- {
- cell = row.GetCell(j);
- if (cell == null)
- {
- dataRow[j] = "";
- }
- else
- {
- //CellType(Unknown = -1,Numeric = 0,String = 1,Formula = 2,Blank = 3,Boolean = 4,Error = 5,)
- switch (cell.CellType)
- {
- case CellType.BLANK:
- dataRow[j] = "";
- break;
- case CellType.NUMERIC:
- short format = cell.CellStyle.DataFormat;
- //对时间格式(2015.12.5、2015/12/5、2015-12-5等)的处理
- if (format == 14 || format == 31 || format == 57 || format == 58)
- dataRow[j] = cell.DateCellValue;
- else
- dataRow[j] = cell.NumericCellValue;
- break;
- case CellType.STRING:
- dataRow[j] = cell.StringCellValue;
- break;
- case CellType.FORMULA:
- dataRow[j] = cell.StringCellValue;
- break;
- }
- }
- }
- dataTable.Rows.Add(dataRow);
- }
- }
- }
- }
- }
- return dataTable;
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- if (fs != null)
- {
- fs.Close();
- }
- return null;
- }
- }
- }
- }
|