private void BtnDataClear_Click(object sender, EventArgs e)
 {
     BLL_Data.ClearData(pno);
     lmb = new List <Model_BillInfo>();
     DgvOrderData.DataSource = lmb;
     lblID.Text           = "流水编号:";
     lblCusName.Text      = "客户名称:";
     lblCusCount.Text     = "商户总量:";
     lblCusAddress.Text   = "客户地址:";
     lblPackageCount.Text = "总包数:";
 }
Exemple #2
0
        private void BtnConfirm_Click(object sender, EventArgs e)
        {
            int packageno = 0;

            try
            {
                packageno = int.Parse(TxtPackageNo.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            int id = 1;

            if (pno == 1)
            {
                if (BLL_Data.DataPosition(packageno, pno))
                {
                    id = BLL_Data.GetIDByPackageNo(packageno, Convert.ToInt32(pno));
                    MessageBox.Show("定位成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("定位失败!");
                }
            }
            else
            {
                if (BLL_Data.DataPosition(packageno, 0, pno))
                {
                    id = BLL_Data.GetIDByPackageNo(packageno, Convert.ToInt32(pno));
                    MessageBox.Show("定位成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("定位失败!");
                }
            }
            DataPosition.ID        = id;
            DataPosition.PackageNo = packageno;
        }
        void SwichPackage()
        {
            if (list.Count > 0 && index > 0)
            {
                int packageNo = list[index - 1].PackageNo;
                BLL_Data.UpdateLabelingStatus(packageNo, pno);
            }

            if (index < list.Count)
            {
                count = int.Parse(list[index].PackageNum);
                Display();
            }
            SetTag(this);                  //调用方法

            float newx = 1;                //窗体宽度缩放比例
            float newy = 1;                //窗体高度缩放比例

            SetControls(newx, newy, this); //随窗体改变控件大小
        }
        private void BgwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1200)
            {
                IpAddress = plcIp,
                Rack      = byte.Parse("0"),
                Slot      = byte.Parse("0")
            };
            OperateResult result = siemensTcpNet.ConnectServer();

            if (!result.IsSuccess)
            {
                SetTag(this);//调用方法
                MessageBox.Show("PLC连接失败,请检查PLC网络");
                Close();
                return;
            }
            list = new List <Model_Data>();
            list = BLL_Data.GetData(pno);
            if (list.Count <= 0)
            {
                MessageBox.Show("请先接收数据!");
            }
            else
            {
                try
                {
                    index = list.Where(item => item.LabelingStatus == "0").Min(item => item.ID) - 1;
                }
                catch
                {
                    MessageBox.Show("已接收数据中都已完成");
                    return;
                }
                count = int.Parse(list[index].PackageNum);
                Display();
                siemensTcpNet.Write(db, (short)0);
                BgwReadPlc.RunWorkerAsync();
            }
        }
 public w_DataReceive()
 {
     InitializeComponent();
     CheckForIllegalCrossThreadCalls = false;
     pno = Convert.ToDecimal(ConfigurationManager.AppSettings["PNo"]);
     try
     {
         lmb = BLL_Data.GetAllBillInfo(pno);
     }
     catch
     {
         MessageBox.Show("数据库连接失败,请检查数据库网络并重新启动程序!");
         foreach (Control item in Controls)
         {
             item.Enabled = false;
         }
         return;
     }
     DgvOrderData.DataSource = lmb;
     if (lmb.Count > 0)
     {
         Model_BillInfo info = new Model_BillInfo();
         int            packageno;
         try
         {
             packageno = lmb.Where(item => item.LabelingStatus == "未完成").Min(item => item.PackageNo);
         }
         catch
         {
             packageno = lmb.Where(item => item.LabelingStatus == "已完成").Max(item => item.PackageNo);
         }
         info                 = lmb.Where(item => item.PackageNo == packageno).FirstOrDefault();
         lblID.Text           = "流水编号:" + packageno.ToString();
         lblCusName.Text      = "客户名称:" + info.CusName;
         lblCusCount.Text     = "商户总量:" + lmb.GroupBy(item => item.BillCode).Select(item => item.Key.Distinct()).Count().ToString();
         lblCusAddress.Text   = "客户地址:" + info.CusAddress.ToString();
         lblPackageCount.Text = "总包数:" + lmb.Count().ToString();
     }
 }
        void SwichPackage()
        {
            if (list.Count > 0 && index > 0)
            {
                int packageNo = list[index - 1].PackageNo;
                BLL_Data.UpdateLabelingStatus(packageNo, pno);
            }

            if (index < list.Count)
            {
                count = int.Parse(list[index].PackageNum);
                Display();
            }


            SetTag(groupBox2);//调用方法


            //float newx = (this.groupBox2.Width) / gX; //窗体宽度缩放比例
            //float newy = (this.groupBox2.Height) / gY;//窗体高度缩放比例
            //SetControls(newx, newy, groupBox2);//随窗体改变控件大小
        }
        private void BgwLoad_DoWork(object sender, DoWorkEventArgs e)
        {
            siemensTcpNet = new SiemensS7Net(SiemensPLCS.S1500)
            {
                IpAddress = plcIp,
                Rack      = byte.Parse("0"),
                Slot      = byte.Parse("0")
            };
            deriction = ConfigurationManager.AppSettings["Deriction"].ToString().ToLower();
            OperateResult result = siemensTcpNet.ConnectServer();

            if (!result.IsSuccess)
            {
                X = this.Width;  //获取窗体的宽度
                Y = this.Height; //获取窗体的高度
                SetTag(this);    //调用方法
                MessageBox.Show("PLC连接失败,请检查PLC网络");
                Close();
                return;
            }

            list = new List <Model_Data>();

            list = BLL_Data.GetData(pno);
            if (list.Count <= 0)
            {
                MessageBox.Show("请先接收数据!");
            }
            else
            {
                index = list.Where(item => item.LabelingStatus == "0").Min(item => item.ID) - 1;
                count = int.Parse(list[index].PackageNum);
                Display();
                siemensTcpNet.Write(db, (short)0);
                BgwReadPlc.RunWorkerAsync();
            }
        }
        private void BGWDataReceive_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                if (choosePath == "")
                {
                    path = Application.StartupPath + @"\数据\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                }
                else
                {
                    path = choosePath;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            string sr = "";

            if (pno == 1)
            {
                List <Model_Data> lmd = FileRead.ReadUnFile(path, out sr);
                if (sr != "" && lmd.Count == 0)
                {
                    MessageBox.Show(sr);
                    return;
                }
                int index = 0;
                int id    = BLL_Data.GetMaxID(pno);
                if (id == 0)
                {
                    index = 0;
                }
                else if (id == lmd.Count)
                {
                    index = lmd.Count;
                    MessageBox.Show("数据已全部接收,如需重新接收数据,请先清除数据");
                }
                else
                {
                    index = id;
                }
                for (int i = index; i < lmd.Count; i++)
                {
                    lmd[i].LabelingStatus = "0";
                    lmd[i].ID             = i + 1;
                    lmd[i].PNo            = pno;
                    BLL_Data.InsertUnnormalData(lmd[i]);
                }
            }
            else
            {
                List <Model_NormalData> lmdn = FileRead.ReadNormalFile(path, out sr);
                if (sr != "" && lmdn.Count == 0)
                {
                    MessageBox.Show(sr);
                    return;
                }
                int index = 0;
                int id    = BLL_Data.GetMaxID(pno);
                if (id == 0)
                {
                    index = 0;
                }
                else if (id == lmdn.Count)
                {
                    index = lmdn.Count;
                    MessageBox.Show("数据已全部接收,如需重新接收数据,请先清除数据");
                    return;
                }
                else
                {
                    index = id;
                }
                for (int i = index; i < lmdn.Count; i++)
                {
                    lmdn[i].LabelingStatus = "0";
                    lmdn[i].ID             = i + 1;
                    lmdn[i].PNo            = pno;
                    BLL_Data.InsertNormalData(lmdn[i]);
                }
            }
            lmb = new List <Model_BillInfo>();
            lmb = BLL_Data.GetAllBillInfo(pno);

            Model_BillInfo info      = new Model_BillInfo();
            int            packageno = lmb.Where(item => item.LabelingStatus == "未完成").Min(item => item.PackageNo);

            info                 = lmb.Where(item => item.PackageNo == packageno).FirstOrDefault();
            lblID.Text           = "流水编号:" + packageno.ToString();
            lblCusName.Text      = "客户名称:" + info.CusName;
            lblCusCount.Text     = "商户总量:" + lmb.GroupBy(item => item.BillCode).Select(item => item.Key.Distinct()).Count().ToString();
            lblCusAddress.Text   = "客户地址:" + info.CusAddress.ToString();
            lblPackageCount.Text = "总包数:" + lmb.Count().ToString();

            DgvOrderData.DataSource = lmb;
        }