Exemplo n.º 1
0
 public async void ReUploadAction()
 {
     Task UploadBarcode = Task.Run(() =>
     {
         try
         {
             string configPath = System.Environment.CurrentDirectory + "\\ReUpdateData.config";
             if (File.Exists(configPath))
             {
                 try
                 {
                     //进程锁住,防止与正在上传的操作冲突
                     lock (GlobalVar.obj2)
                     {
                         FileStream fileStream    = new FileStream(configPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                         BinaryFormatter mBinFmat = new BinaryFormatter();
                         UploadData Ud            = mBinFmat.Deserialize(fileStream) as UploadData;
                         fileStream.Close();
                         foreach (var item in Ud.ReUpdate)
                         {
                             lock (GlobalVar.obj2)
                             {
                                 DataSet ds = webServiceSZ.ws.getDataFromSer("MAC", "MAC", GlobalVar.MachineID, "MWS01", "MWS_ZX01", item.Item1, item.Item2.ToString());
                                 GlobalVar.AddMessage("重传信息;" + item.Item1);
                                 GlobalVar.AddMessage(ds.Tables[0].Rows[0].ItemArray[0].ToString());
                                 if (ds.Tables[0].Rows[0].ItemArray[0].ToString().Contains("OK"))
                                 {
                                     Ud.ReUpdate.Remove(item);
                                 }
                             }
                             System.Threading.Thread.Sleep(1000);
                         }
                         fileStream        = new FileStream(configPath, FileMode.Create);
                         BinaryFormatter b = new BinaryFormatter();
                         b.Serialize(fileStream, Ud);
                         fileStream.Close();
                     }
                 }
                 catch (Exception ex)
                 {
                     GlobalVar.AddMessage(ex.Message);
                 }
             }
         }
         catch { }
     });
     await UploadBarcode;
 }
Exemplo n.º 2
0
        private void SaveCSVfileBarcode(string bar, int index)
        {
            string filepath = "F:\\生产记录\\条码" + GlobalVar.GetBanci() + ".csv";

            if (!Directory.Exists("F:\\生产记录"))
            {
                Directory.CreateDirectory("F:\\生产记录");
            }
            try
            {
                if (!File.Exists(filepath))
                {
                    string[] heads = { "Date", "Index", "Barcode", "MachineID", "UserID", "ProductName", "MachineName", "FactoryArea", "FactorySeparation", "ZhijuClass", "Barcodeproofing", "scancodetype", "CCD", "NNNN", };
                    Csvfile.AddNewLine(filepath, heads);
                }
                string[] conte = { System.DateTime.Now.ToString(), index.ToString(), bar, GlobalVar.MachineID, GlobalVar.UserID, GlobalVar.ProductName, GlobalVar.MachineName, GlobalVar.FactoryArea, GlobalVar.FactorySeparation, GlobalVar.ZhijuClass, GlobalVar.Barcodeproofing, GlobalVar.scancodetype, GlobalVar.CCD, GlobalVar.NNNN, };
                Csvfile.AddNewLine(filepath, conte);

                MESDataItem tr = new MESDataItem()
                {
                    Date = System.DateTime.Now.ToString(), Index = index.ToString(), Barcode = bar, MachineID = GlobalVar.MachineID, UserID = GlobalVar.UserID, ProductName = GlobalVar.ProductName, MachineName = GlobalVar.MachineName, FactoryArea = GlobalVar.FactoryArea, FactorySeparation = GlobalVar.FactorySeparation, ZhijuClass = GlobalVar.ZhijuClass, Barcodeproofing = GlobalVar.Barcodeproofing, scancodetype = GlobalVar.scancodetype, CCD = GlobalVar.CCD, NNNN = GlobalVar.NNNN,
                };
                lock (GlobalVar.obj1)
                {
                    // GlobalVar.AlarmRecord.Add(tr);
                    GlobalVar.MESDataRecordQueue.Enqueue(tr);
                }
                string para1 = GlobalVar.MAC + "|" + GlobalVar.CCD + "," + GlobalVar.NNNN + "," + GlobalVar.ProductName + "," + GlobalVar.MachineID + "," + GlobalVar.UserID + "," + GlobalVar.MachineName + "," + GlobalVar.ZhijuClass + "," + GlobalVar.Barcodeproofing + "," + GlobalVar.FactoryArea + "," + GlobalVar.FactorySeparation + "," + GlobalVar.scancodetype + "," + bar;
                //进程锁住,防止与自动重传操作冲突
                lock (GlobalVar.obj2)
                {
                    DataSet ds = webServiceSZ.ws.getDataFromSer("MAC", "MAC", GlobalVar.MachineID, "MWS01", "MWS_ZX01", para1, System.DateTime.Now.ToShortDateString());
                    GlobalVar.AddMessage("上传信息;" + para1);
                    GlobalVar.AddMessage(ds.Tables[0].Rows[0].ItemArray[0].ToString());
                    if (!ds.Tables[0].Rows[0].ItemArray[0].ToString().Contains("OK"))
                    {
                        string configPath = System.Environment.CurrentDirectory + "\\ReUpdateData.config";
                        if (File.Exists(configPath))
                        {
                            try
                            {
                                //如果文件存在则先读出来
                                FileStream      fileStream = new FileStream(configPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                BinaryFormatter mBinFmat   = new BinaryFormatter();
                                UploadData      Ud         = mBinFmat.Deserialize(fileStream) as UploadData;
                                fileStream.Close();
                                //追加记录,并覆盖原文件
                                Ud.ReUpdate.Add(new Tuple <string, DateTime>(para1, DateTime.Now));
                                fileStream = new FileStream(configPath, FileMode.Create);
                                BinaryFormatter b = new BinaryFormatter();
                                b.Serialize(fileStream, Ud);
                                fileStream.Close();
                                GlobalVar.AddMessage(bar + " 上传失败,保存到本地");
                            }
                            catch (Exception ex)
                            {
                                GlobalVar.AddMessage(ex.Message);
                            }
                        }
                        else
                        {
                            try
                            {
                                //如果文件不存在则直接创建
                                UploadData Ud = new UploadData();
                                Ud.ReUpdate.Add(new Tuple <string, DateTime>(para1, DateTime.Now));
                                FileStream      fileStream = new FileStream(configPath, FileMode.Create);
                                BinaryFormatter b          = new BinaryFormatter();
                                b.Serialize(fileStream, Ud);
                                fileStream.Close();
                                GlobalVar.AddMessage(bar + " 上传失败,保存到本地");
                            }
                            catch (Exception ex)
                            {
                                GlobalVar.AddMessage(ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalVar.AddMessage(ex.Message);
            }
        }