Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Copy all files into the CF card
            System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
            var targetDri = allDrives.Where(x => x.DriveType.ToString().ToUpper() != "CDROM" && x.VolumeLabel == "NC_PROGRAM");


            if (targetDri.Count() > 0)
            {
                string outputfolder  = Program.InfoPath + productList1.listBox1.SelectedItem.ToString() + "\\NC\\COUPON\\";
                string newfoldername = targetDri.First().RootDirectory.FullName;
                BackupOperation.backupfolder(newfoldername);
                List <FileInfo> files = new List <FileInfo>();
                files.WalkTree(outputfolder, false);
                files.copyto(newfoldername);
            }
        }
Exemplo n.º 2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int k = e.ColumnIndex;
            int l = e.RowIndex;

            if (l >= 0)
            {
                currentrow = l;
                dataGridView1.Rows[currentrow].Selected = true;
                currentpos = dataGridView1.FirstDisplayedScrollingRowIndex;
                DataRowView temprow = (DataRowView)dataGridView1.Rows[l].DataBoundItem;
                //  string liushui = temprow[5].ToString();
                bool manager = Program.ManagerActived;

                switch (k)
                {
                case 0:
                    if (checkBox1.Checked == false)
                    {
                        //产品
                        listBox2.SelectedItem = temprow[2].ToString();
                        textBox1.Text         = temprow[3].ToString();
                        string startdatestr    = temprow[4].ToString();
                        string enddatestr      = temprow[5].ToString();
                        string transferdatestr = temprow[6].ToString();

                        if (startdatestr != "" && !startdatestr.Contains("0000"))
                        {
                            dateTimePicker1.Value = DateTime.Parse(startdatestr);
                            checkBox4.Checked     = false;
                        }
                        else
                        {
                            checkBox4.Checked = false;
                        }
                        if (enddatestr != "" && !enddatestr.Contains("0000"))
                        {
                            dateTimePicker2.Value = DateTime.Parse(enddatestr);
                            checkBox3.Checked     = false;
                        }
                        else
                        {
                            checkBox3.Checked = true;
                        }


                        if (transferdatestr != "" && !transferdatestr.Contains("0000"))
                        {
                            dateTimePicker3.Value = DateTime.Parse(transferdatestr);
                            checkBox2.Checked     = false;
                        }
                        else
                        {
                            checkBox2.Checked = true;
                        }
                        comboBox1.Text = temprow[7].ToString();
                        textBox3.Text  = temprow[8].ToString();
                        textBox2.Text  = temprow[10].ToString();
                    }

                    label8.Text = temprow[9].ToString();
                    // startdate = true;
                    //  enddate = true;
                    // transferdate = true;


                    break;

                case 1:
                    RNC f = new RNC();
                    f.Show();
                    f.product_filter = temprow["产品名称"].ToString() + "_" + temprow["产品架次"].ToString();

                    //  f.rncrf(temprow[2].ToString(), temprow[3].ToString());


                    break;

                case 2:

                    //Get the NC program
                    //Auto-copy it to G:\

                    //System.IO.DriveInfo[] allDrivess = System.IO.DriveInfo.GetDrives();
                    //Console.Write(allDrivess.First().VolumeLabel);

                    if (Program.userID.Split('_')[0] == "192.168.13.68" || Program.ManagerActived == true)
                    {
                        string proname = temprow[0].ToString();

                        //     proname = proname + "process";

                        string folderpath = Program.InfoPath + temprow["产品名称"].ToString() + "_" + proname + "\\NC\\";

                        string progname = Program.prodTable.Select("图号='" + proname + "'").First()["程序编号"].ToString();
                        string filepath = folderpath + "\\" + progname;



                        if (System.IO.Directory.Exists(folderpath) && File.Exists(filepath))

                        {
                            //校验MD5

                            string curMD5 = localMethod.GetMD5HashFromFile(filepath);
                            Dictionary <string, string> p1 = new Dictionary <string, string>();
                            string preMD5;
                            try
                            {
                                string preJson = DbHelperSQL.getlist("select 备注 from 产品数模 where 产品名称='" + temprow["产品名称"].ToString() + "' and 文件类型='Process'").First();

                                JsonSerializer serializer = new JsonSerializer();
                                // JsonReader reader = new JsonTextReader(new StringReader(preJson));
                                StringReader sr = new StringReader(preJson);
                                p1     = (Dictionary <string, string>)serializer.Deserialize(new JsonTextReader(sr), typeof(Dictionary <string, string>));
                                preMD5 = p1["MD5"];
                            }
                            catch (Exception ke)
                            {
                                MessageBox.Show("编程者未正确输出程序,请联系编程者!\r额外信息:\r" + ke.Message);
                                return;
                            }
                            if (preMD5 == curMD5)
                            {
                                //Copy all files into the CF card
                                System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
                                var targetDri = allDrives.Where(x => x.DriveType.ToString().ToUpper() != "CDROM" && x.VolumeLabel == "NC_PROGRAM");


                                if (targetDri.Count() > 0)
                                {
                                    string newfoldername = targetDri.First().RootDirectory.FullName;


                                    BackupOperation.backupfolder(newfoldername);

                                    localMethod.creatDir(newfoldername);

                                    List <FileInfo> files = new List <FileInfo>();
                                    files.WalkTree(folderpath, false);
                                    files.copyto(newfoldername);
                                    if (p1.ContainsKey("COPYTIME"))
                                    {
                                        p1["COPYTIME"] = DateTime.Now.ToString();
                                    }
                                    else
                                    {
                                        p1.Add("COPYTIME", DateTime.Now.ToString());
                                    }


                                    DbHelperSQL.ExecuteSql("update 产品数模 set 备注='" + localMethod.ToJson(p1) + "' where 产品名称='" + temprow["产品名称"].ToString() + "' and 文件类型='Process'");

                                    MessageBox.Show("请在操作记录或相关文件上记录MD5值:\r" + curMD5 + "\r\t该程序的生成时间为:\r" + p1["TIME"]);
                                    System.Diagnostics.Process.Start("explorer.exe", newfoldername);
                                }

                                else
                                {
                                    MessageBox.Show("未连接到CF卡(NC_PROGRAM),请确保你在我的电脑中已看到CF卡的盘符!");
                                    return;
                                }
                            }
                            else
                            {
                                MessageBox.Show("MD5校验未通过,联系编程者重新输出!");
                                return;
                            }
                        }
                        else
                        {
                            MessageBox.Show("NC程序不存在,联系工艺员或编程者!");
                            return;
                        }

                        //  if (manager)
                        //   {



                        //f1.inputValue = proname;
                        //f1.Show();
                    }
                    else
                    {
                        MessageBox.Show("必须在自动钻铆现场工作站上使用,并插入CF卡!");
                    }
                    break;

                case 3:

                    paperWork paperf = new paperWork();
                    paperf.Show();
                    paperf.ppworkrf(temprow[2].ToString(), temprow[3].ToString());
                    break;


                case 4:



                    //查看试片列表

                    string prodname   = temprow["图号"].ToString();
                    string chnname    = temprow["产品名称"].ToString();
                    string fuseno     = temprow["产品架次"].ToString();
                    string foldername = Program.InfoPath + chnname + "_" + prodname + "\\" + fuseno + "\\Inspection\\";

                    //刷新试片编号

                    DbHelperSQL.ExecuteSqlTran(AutorivetDB.rfcouponno(prodname));


                    localMethod.creatDir(foldername);


                    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(foldername);
                    int fileNum = dir.GetFiles().Length;

                    if (fileNum > 2)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", foldername);
                        return;
                    }

                    //               Microsoft.Office.Interop.Excel.Application app =
                    //  new Microsoft.Office.Interop.Excel.ApplicationClass();


                    //app.Visible = false;
                    string    processtb    = prodname.Replace("-001", "Process");
                    DataTable coupon_table = DbHelperSQL.Query("select * from (select * from 试片列表 where 产品图号='" + prodname + "') aa inner join " + processtb + " bb  on aa.程序段编号=bb.UUID").Tables[0];
                    //查询程序编号

                    string programno = AutorivetDB.queryno(prodname, "程序编号");


                    foreach (DataRow pp in coupon_table.Rows)
                    {
                        string progpart = pp["程序段编号"].ToString();


                        //取回程序段的ID号
                        string progid = pp["ID"].ToString();



                        string couponno = "T" + pp["编号"].ToString();
                        string fstname  = progpart.Split('_')[1];

                        string skinthk = pp["蒙皮厚度"].ToString();
                        string secmat  = pp["二层材料"].ToString();
                        string secthk  = pp["二层厚度"].ToString();
                        if (skinthk.Length < 3)
                        {
                            skinthk = "0" + skinthk;
                        }
                        if (secthk.Length < 3)
                        {
                            secthk = "0" + secthk;
                        }

                        if (fstname.Contains("B0206002"))
                        {
                            var    wBook    = new excelMethod(Program.InfoPath + "SAMPLE\\COUPON\\HI_LITE.xls");
                            string filename = foldername + progid + "_" + couponno + "_" + progpart + "_" + secthk + ".xls";
                            if (File.Exists(filename))
                            {
                                continue;
                            }


                            wBook.SaveAs(filename);

                            wBook.Set_CellValue(2, 8, (programno + "/" + progid + "/" + progpart));
                            wBook.Set_CellValue(5, 8, prodname);
                            //  wBook.Set_CellValue(7, 8, fuseno);
                            wBook.Set_CellValue(9, 8, couponno);
                            wBook.Set_CellValue(11, 4, fstname);
                            //蒙皮试片


                            wBook.Set_CellValue(9, 5, "C1-SKIN-" + skinthk);



                            //二层材料


                            wBook.Set_CellValue(9, 6, "C1-" + secmat + "-" + secthk);



                            wBook.Save();
                            wBook.Quit();
                        }

                        else
                        {
                            var wBook = new excelMethod(Program.InfoPath + "SAMPLE\\COUPON\\RIVET.xls");
                            //   progid = pp["ID"].ToString();
                            string filename = foldername + progid + "_" + couponno + "_" + progpart + "_" + secthk + "_BEFORE.xls";

                            if (File.Exists(filename))
                            {
                                continue;
                            }

                            wBook.SaveAs(filename);
                            //  Microsoft.Office.Interop.Excel.Worksheet wSheet = wBook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
                            wBook.Set_CellValue(2, 10, programno + "/" + progid + "/" + progpart);
                            wBook.Set_CellValue(5, 10, prodname);
                            //wBook.Set_CellValue(7, 10, fuseno);
                            wBook.Set_CellValue(12, 10, couponno + "_BEFORE");
                            wBook.Set_CellValue(14, 6, fstname);
                            //蒙皮试片

                            wBook.Set_CellValue(12, 7, "C1-SKIN-" + skinthk);



                            //二层材料


                            wBook.Set_CellValue(12, 8, "C1-" + secmat + "-" + secthk);



                            wBook.Save();

                            wBook.Set_CellValue(12, 10, couponno + "_AFTER");

                            filename = foldername + progid + "_" + couponno + "_" + progpart + "_" + secthk + "_AFTER.xls";
                            if (File.Exists(filename))
                            {
                                continue;
                            }

                            wBook.SaveAs(filename);

                            wBook.Quit();
                        }
                    }

                    //生成产品检查单

                    string newpath = foldername + prodname + "_INSPECTION.doc";
                    File.Copy(Program.InfoPath + "SAMPLE\\PRODUCT_INSPECTION.docx", newpath, true);
                    var myAO = wordMethod.opendoc(newpath);

                    wordMethod.SearchReplace(myAO, "[1]", prodname);
                    // wordMethod.SearchReplace(myAO, "[2]", fuseno);
                    wordMethod.SearchReplace(myAO, "[3]", chnname);
                    myAO.Save();

                    myAO.Application.Quit();

                    //生成参数检查单
                    newpath = foldername + prodname + "_PARA_INSPECTION.xlsx";
                    var tianchong = new Dictionary <string, DataTable>();

                    // List<string> tianchongname=new List<string> ();


                    tianchong.Add(prodname, AutorivetDB.getparatable(prodname));
                    //  tianchongname.Add(productnametrim);

                    OfficeMethod.excelMethod.SaveDataTableToExcelTran(tianchong, newpath);


                    System.Diagnostics.Process.Start("explorer.exe", foldername);


                    break;



                    //case 3:



                    //     Dictionary<string, string> tmp = new Dictionary<string, string>();
                    //     tmp.Add("类型", "补铆");
                    //     //建立补铆文件夹
                    //     string rootdir =Program.InfoPath  + temprow[2].ToString() + "_" + temprow[0].ToString() + "\\" + temprow[3].ToString() + "\\补铆\\" ;


                    //     if (!System.IO.Directory.Exists(rootdir))
                    //     {
                    //         localMethod.creatDir(rootdir);

                    //     }
                    //     System.Diagnostics.Process.Start("explorer.exe", rootdir);
                    //     tmp.Add("目录地址", rootdir);
                    //     //用于信息传递


                    //     //名称
                    // string prodname = temprow[2].ToString();

                    // tmp.Add("中文名称", prodname+"壁板");
                    // tmp.Add("名称", prodname );



                    ////架次
                    //string jiaci = temprow[3].ToString();
                    //tmp.Add("架次", jiaci);



                    //     tmp.Add("保存地址", rootdir  + temprow[0].ToString() +"_"+ temprow[1].ToString() + "_补铆.doc");


                    //     AO f2=new AO();

                    //     f2.rncaao=tmp;
                    //     f2.tianchong();
                    //     f2.Show();



                    //     break;
                }
            }
        }