yangle
2024-11-29 1d9f82659dbfdfd6ac0ddbb33f1fd5af1164d939
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadCoordinateExcelFrom.cs
@@ -6,6 +6,8 @@
using NPOI.XSSF.UserModel; // 对于.xlsx文件  
using NPOI.HSSF.UserModel; // 对于.xls文件  
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing;
namespace WFormReadData_SMR
{
@@ -30,6 +32,11 @@
            //路径只读
            this.txtLj.ReadOnly = true;
            this.txtPcm.ReadOnly = true;
            //制单编码只读
            this.txtHMakerNumber.ReadOnly = true;
            //制单人提示
            this.txtHMaker.ForeColor = Color.LightGray;
            this.txtHMaker.Text = "请输入用户编码!";
            SelectHProList();
        }
@@ -42,7 +49,6 @@
                MessageBox.Show("流转卡没有扫描!");
            }
            else {
                //路径赋值给文本
                using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
                {
@@ -55,8 +61,8 @@
                        string selectedFolderPath = folderBrowserDialog.SelectedPath;
                        // 使用 selectedFolderPath 进行后续操作,例如显示在文本框中  
                        this.txtLj.Text = selectedFolderPath;
                        //GetCSV_Read(selectedFolderPath);
                        GetExcel_Read(selectedFolderPath);
                        GetCSV_Read(selectedFolderPath);
                        //GetExcel_Read(selectedFolderPath);
                    }
                }
            }
@@ -114,8 +120,8 @@
                }
            }
            //显示数据
            ShowData(ds);
            //显示数据  CMR-L-066 轮廓仪
            ShowData(ds, "CMR-L-066");
        }
        //根据文件路径找到对应文件 并获取对应的数据
@@ -253,8 +259,8 @@
                    }
                }
            }
            //显示数据
            ShowData(ds);
            //显示数据 CMR-L-067 三坐标
            ShowData(ds, "CMR-L-067");
        }
        //根据文件路径找到对应文件 并获取对应的数据
@@ -321,7 +327,7 @@
        }
        //把数据显示在页面上
        public void ShowData(DataSet ds) {
        public void ShowData(DataSet ds,string HNumber) {
            //清空网格内容
            ListData.Items.Clear();
            //清空表格内容
@@ -335,14 +341,16 @@
            dataTable.Columns.Add("Actual");
            dataTable.Columns.Add("HUpLimit");
            dataTable.Columns.Add("HDownLimit");
            dataTable.Columns.Add("HInspectInstruMentID");
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                //修改是在哪个设备上进行的数据采集 b.HInspectInstruMentID=1  三坐标1    轮廓仪2
                DataSet dataSet = oCN.RunProcReturn(@"select a.HInterID HQCSchemeID,b.HQCCheckItemID, ch.HNumber HQCCheckItemNumber,m.HNumber,HUpLimit,HDownLimit,HTargetVal
                DataSet dataSet = oCN.RunProcReturn(@"select b.HInspectInstruMentID,a.HInterID HQCSchemeID,b.HQCCheckItemID, ch.HNumber HQCCheckItemNumber,m.HNumber,HUpLimit,HDownLimit,HTargetVal
from Sc_ProcessExchangeBillMain pr with(nolock)
inner join Gy_QCCheckProjectMain a with(nolock) on pr.HMaterID=a.HMaterID
inner join Gy_QCCheckProjectSub b with(nolock) on a.HInterID=b.HInterID and  b.HInspectInstruMentID=1
inner join Gy_QCCheckProjectSub b with(nolock) on a.HInterID=b.HInterID
inner join Gy_InspectInstruMent men  with(nolock) on b.HInspectInstruMentID=men.HItemID   and men.HNumber='"+ HNumber + @"'
left join Gy_Material m with(nolock) on a.HMaterID=m.HItemID
left join Gy_QCCheckItem ch with(nolock) on b.HQCCheckItemID=ch.HItemID  
where pr.HBillNo='" + this.txtLzk.Text + "'", "Gy_QCCheckProjectMain");
@@ -367,6 +375,7 @@
                                dr["Actual"] = ds.Tables[i].Rows[k]["Actual"].ToString();
                                dr["HUpLimit"] = dataSet.Tables[0].Rows[j]["HUpLimit"].ToString();
                                dr["HDownLimit"] = dataSet.Tables[0].Rows[j]["HDownLimit"].ToString();
                                dr["HInspectInstruMentID"] = dataSet.Tables[0].Rows[j]["HInspectInstruMentID"].ToString();
                                ListData.Items.Add("检验项目:" + ds.Tables[i].Rows[k]["Characteristic"].ToString() + ",实测值:" + ds.Tables[i].Rows[k]["Actual"].ToString() + ",上公差:" + dataSet.Tables[0].Rows[j]["HUpLimit"].ToString() + ",下公差:" + dataSet.Tables[0].Rows[j]["HDownLimit"].ToString());
                                break;
                            }
@@ -490,10 +499,17 @@
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0" +
                        "," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','"+ dataTable.Rows[i]["HQCStd"].ToString() + "','" + HLastResult + "'" +
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + dataTable.Rows[i]["Actual"].ToString() + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'1',0,'"+ HLastResult + "'" +
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + dataTable.Rows[i]["Actual"].ToString() + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" +
                        ") ");
                    }
                    DataSet SetData = oCN.RunProcReturn("select  HMakeDate from QC_TakeSampleCheckBillMain where HInterID =" + this.HTakeSampleCheckBillID.Text, "QC_TakeSampleCheckBillMain");
                    string HMakeDate = "";
                    if (SetData.Tables[0].Rows.Count > 0)
                    {
                        HMakeDate = SetData.Tables[0].Rows[0]["HMakeDate"].ToString();
                    }
                    //主表
                    oCN.RunProc("Insert Into QC_FirstPieceCheckBillMain " +
                        "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
@@ -502,13 +518,14 @@
                        ",HProcExchBillNo,HProcExchQty,HMaterID,HFirstCheckEmp,HLastResult" +
                        ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HShiftsID,HErrTreatment" +
                        ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo,HProcID" +
                        ") " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,getdate(),'',getdate()" +
                        ",HBatchNo) " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'"+ HMakeDate + "','" + this.txtHMaker.Text + "',getdate()" +
                        "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                        "," + HSourceID + "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HPlanQty + "," + HProcExchInterID + "," + HProcExchEntryID +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'', " + HLastResults +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'"+this.labHMakerID.Text + "', " + HLastResults +
                        "," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + ",0,''" +
                        "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "',"+ HProcID + ") ");
                        "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "'," + HProcID + "" +
                        ",'" + this.txtPcm.Text + "') ");
                    oCN.Commit();
@@ -590,7 +607,13 @@
                        + HInterID + ",'" + HBillNo + "'," + (i + 1) + ",''" +
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','"+ dataTable.Rows[i]["HQCStd"].ToString() + "','" + HLastResult + "'" +
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + dataTable.Rows[i]["Actual"].ToString() + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'1',0,'"+ HLastResult + "'" + ") ");
                        ",'" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "',''" + ",0,0,0,0,0,0,'',0,'" + dataTable.Rows[i]["Actual"].ToString() + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() + "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" + ") ");
                    }
                    DataSet SetData = oCN.RunProcReturn("select  HMakeDate from QC_TakeSampleCheckBillMain where HInterID =" + this.HTakeSampleCheckBillID.Text, "QC_TakeSampleCheckBillMain");
                    string HMakeDate = "";
                    if (SetData.Tables[0].Rows.Count > 0)
                    {
                        HMakeDate = SetData.Tables[0].Rows[0]["HMakeDate"].ToString();
                    }
                    //主表
@@ -600,13 +623,13 @@
                        ",HSourceID,HICMOInterID,HICMOBillNo,HICMOQty,HProcExchInterID,HProcExchEntryID" +
                        ",HProcExchBillNo,HProcExchQty,HMaterID,HFirstCheckEmp,HLastResult" +
                        ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HShiftsID,HErrTreatment" +
                        ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo,HProcID) " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,getdate(),'',getdate()" +
                        ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo,HProcID,HBatchNo) " +
                        " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'"+ HMakeDate + "','"+this.txtHMaker.Text + "',getdate()" +
                        "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                        "," + HSourceID + "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HPlanQty + "," + HProcExchInterID + "," + HProcExchEntryID +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'', " + HLastResults +
                        ",'" + HProcExchBillNo + "'," + HQty + "," + HMaterID + ",'" + this.labHMakerID.Text + "', " + HLastResults +
                        "," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + ",0,''" +
                        "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "',"+ HProcID + ") ");
                        "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "',"+ HProcID + ",'" + this.txtPcm.Text + "') ");
                    oCN.Commit();
@@ -687,8 +710,15 @@
                        ",getdate(),0,''," + HProcExchInterID +
                        "," + HProcExchEntryID + ",'" + HProcExchBillNo + "','',0,0,0," + dataTable.Rows[i]["CharacteristicID"].ToString() + ",'" + dataTable.Rows[i]["HQCStd"].ToString() + "','','" + HLastResult + "'" +
                        ",0,'',0,0,0,0,0,0,'',0,'" + dataTable.Rows[i]["Actual"].ToString() + "','" + dataTable.Rows[i]["HQCStd"].ToString() + "','" + dataTable.Rows[i]["HUpLimit"].ToString() + "','" + dataTable.Rows[i]["HDownLimit"].ToString() +
                                "','','',0,'',0,'"+ HLastResult + "'" +
                                "','','',0,'2'," + dataTable.Rows[i]["HInspectInstruMentID"].ToString() + ",'" + HLastResult + "'" +
                                ",'"+ dataTable.Rows[i]["HQCStd"].ToString() + "') ");
                    }
                    DataSet SetData = oCN.RunProcReturn("select  HMakeDate from QC_TakeSampleCheckBillMain where HInterID =" + this.HTakeSampleCheckBillID.Text, "QC_TakeSampleCheckBillMain");
                    string HMakeDate = "";
                    if (SetData.Tables[0].Rows.Count > 0)
                    {
                        HMakeDate = SetData.Tables[0].Rows[0]["HMakeDate"].ToString();
                    }
                    //主表
@@ -704,14 +734,15 @@
                    ",HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType,HICMOEntryID,HQCSchemeID,HICMOQty" +
                    ",HProcExchQty,HShiftsID,HErrTreatment" +
                    ",HTakeSampleCheckBillID,HTakeSampleCheckBillNo" +
                    ") " +
                    " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,getdate(),'',getdate()" +
                    ",HBatchNo,HCheckerResult) " +
                    " values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',1,'"+ HMakeDate + "','" + this.txtHMaker.Text + "',getdate()" +
                    "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",''" +
                    "," + HICMOInterID + ",'" + HICMOBillNo + "'," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "'" +
                    "," + HMaterID + "," + HProcID + "," + HSourceID + ",0,0,0,0,0,0,'" + HLastResults + "'" +
                    "," + HMaterID + "," + HProcID + "," + HSourceID + ",0,0,0,0,0," + this.labHMakerID.Text + ",'" + HLastResults + "'" +
                    ",'','',0,'',''" +
                    ",0,0,'',0,0,0,0,'',0," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcExchBillNo + "',''," + HICMOEntryID + "," + HQCSchemeID + "," + HPlanQty + "," + HQty + ",0,''" +
                    "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "') ");
                    "," + this.HTakeSampleCheckBillID.Text + ",'" + this.HTakeSampleCheckBillNo.Text + "'" +
                    ",'" + this.txtPcm.Text + "','"+ HLastResults + "') ");
                    oCN.Commit();
@@ -731,7 +762,14 @@
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHBardCode(this.txtLzk.Text);
                if (this.txtHMakerNumber.Text == "")
                {
                    MessageBox.Show("请输入制单人信息!");
                }
                else {
                    SelectHBardCode(this.txtLzk.Text);
                }
            }
        }
@@ -741,32 +779,36 @@
            try
            {
                string cmbPro = this.cmbPro.SelectedValue.ToString();
                DataSet ds = oCN.RunProcReturn("select  * from h_v_Sc_ProcessExchangeBillQuerySub where 单据号='" + HBillNo + "' and  HProcID='"+ cmbPro + "'", "h_v_Sc_ProcessExchangeBillQuerySub");
               DataSet ds = oCN.RunProcReturn("select  * from h_v_QC_TakeSampleCheckBillList where 单据号='" + HBillNo + "' and  HProcID='" + cmbPro + "'", "h_v_QC_TakeSampleCheckBillList");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    ds = oCN.RunProcReturn("select  * from h_v_QC_TakeSampleCheckBillList where 单据号='" + HBillNo + "' and  HProcID='" + cmbPro + "'", "h_v_QC_TakeSampleCheckBillList");
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        MessageBox.Show("当前工序对应的单据,查无数据!");
                    }
                    else
                    {
                        string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
                        this.txtPcm.Text = HProjectNum.Split('-')[0];
                        this.txtLzk.Text = ds.Tables[0].Rows[0]["工序流转卡号"].ToString();
                        this.HTakeSampleCheckBillID.Text = ds.Tables[0].Rows[0]["hmainid"].ToString();
                        this.HTakeSampleCheckBillNo.Text = ds.Tables[0].Rows[0]["单据号"].ToString();
                        this.txtLzk.ReadOnly = true;
                    }
                    MessageBox.Show("当前工序对应的取样单据,查无数据!");
                }
                else
                {
                    string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
                    this.txtPcm.Text = HProjectNum.Split('-')[0];
                    this.HTakeSampleCheckBillID.Text = "0";
                    this.HTakeSampleCheckBillNo.Text = "";
                    this.txtLzk.Text = ds.Tables[0].Rows[0]["工序流转卡号"].ToString();
                    this.HTakeSampleCheckBillID.Text = ds.Tables[0].Rows[0]["hmainid"].ToString();
                    this.HTakeSampleCheckBillNo.Text = ds.Tables[0].Rows[0]["单据号"].ToString();
                    this.txtLzk.ReadOnly = true;
                    this.label2.Text = "流转卡:";
                }
                //DataSet ds = oCN.RunProcReturn("select  * from h_v_Sc_ProcessExchangeBillQuerySub where 单据号='" + HBillNo + "' and  HProcID='"+ cmbPro + "'", "h_v_Sc_ProcessExchangeBillQuerySub");
                //if (ds.Tables[0].Rows.Count == 0)
                //{
                //}
                //else
                //{
                //    string HProjectNum = ds.Tables[0].Rows[0]["HProjectNum"].ToString();
                //    this.txtPcm.Text = HProjectNum.Split('-')[0];
                //    this.HTakeSampleCheckBillID.Text = "0";
                //    this.HTakeSampleCheckBillNo.Text = "";
                //    this.txtLzk.ReadOnly = true;
                //}
            }
            catch (Exception e)
            {
@@ -801,8 +843,8 @@
        private void ReadCoordinateExcelFrom_Activated(object sender, EventArgs e)
        { 
            //光标选中流转卡
            this.txtLzk.Focus();
            //光标选中制单人
            this.txtHMaker.Focus();
        }
        private void ReadCoordinateExcelFrom_FormClosing(object sender, FormClosingEventArgs e)
@@ -812,5 +854,58 @@
                e.Cancel = true;
            }
        }
        private void txtHMaker_Leave(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtHMaker.Text))
            {
                this.txtHMaker.ForeColor = Color.LightGray;
                txtHMaker.Text = "请输入用户编码!";
            }
        }
        private void txtHMaker_Enter(object sender, EventArgs e)
        {
            if (txtHMaker.Text.Trim() == "请输入用户编码!")
            {
                txtHMaker.Text = "";
                this.txtHMaker.ForeColor = Color.Black;
            }
        }
        private void txtHMaker_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SelectHMaker(this.txtHMaker.Text);
            }
        }
        //查询职员信息
        public void SelectHMaker(string txtHMaker) {
            try
            {
                DataSet ds = oCN.RunProcReturn("select  HItemID,HName,HNumber from Gy_Employee where HNumber='" + txtHMaker + "' or HName ='" + txtHMaker + "'", "Gy_Employee");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string HName = ds.Tables[0].Rows[0]["HName"].ToString();
                    string HMakerID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                    string HNumber = ds.Tables[0].Rows[0]["HNumber"].ToString();
                    this.txtHMaker.Text = HName;
                    this.txtHMakerNumber.Text = HNumber;
                    this.labHMakerID.Text = HMakerID;
                    this.txtHMaker.ReadOnly = true;
                }
                else
                {
                    MessageBox.Show(this, txtHMaker + ",查无数据,可能是输入编码有误!", "提示");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "提示");
            }
        }
    }
}