示例#1
0
文件: frmCL.cs 项目: tpc707494/C-Erp
 private void CLstart()
 {
     if (this.dgvData.CurrentRow.Index < 0)
     {
         this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
         this.TSsound.Play();
         frmError frmError = new frmError("当前称料行不存在!请再次查询!");
         int      num      = (int)frmError.ShowDialog((IWin32Window)this);
         frmError.Close();
     }
     else
     {
         //DBpf dbpf = new DBpf(Settings.Default.DBconn);
         //T_PFmain tPfmain = dbpf.T_PFmain.Where<T_PFmain>((Expression<Func<T_PFmain, bool>>)(a => a.danhao == this.txtLDH.Text)).SingleOrDefault<T_PFmain>();
         T_PFmain tPfmain = db.Queryable <T_PFmain>()
                            .Where(a => a.danhao == this.txtLDH.Text)
                            .First();
         if (tPfmain == null || tPfmain.sta != "已审核")
         {
             //dbpf.Dispose();
             this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
             this.TSsound.Play();
             frmError frmError = new frmError("料单未审核或不存在!请再次查询!");
             int      num      = (int)frmError.ShowDialog((IWin32Window)this);
             frmError.Close();
         }
         else
         {
             //T_PFdata tPfdata = dbpf.T_PFdata.Where<T_PFdata>((Expression<Func<T_PFdata, bool>>)(a => a.SN == (long)this.dgvData.CurrentRow.Cells[this.colSN.Name].Value)).SingleOrDefault<T_PFdata>();
             T_PFdata tPfdata = db.Queryable <T_PFdata>()
                                .Where(a => a.SN == (long)this.dgvData.CurrentRow.Cells[this.colSN.Name].Value)
                                .First();
             if (tPfdata == null || tPfdata.ranliao != this.dgvData.CurrentRow.Cells[this.colRL.Name].Value.ToString())
             {
                 //dbpf.Dispose();
                 this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
                 this.TSsound.Play();
                 frmError frmError = new frmError("料单数据发生了改变!请再次查询!");
                 int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                 frmError.Close();
             }
             else
             {
                 Decimal num1 = new Decimal(0);
                 Decimal num2;
                 if (this.txtLDH.Text.StartsWith("LD") || this.txtLDH.Text.Length == 10 && this.txtLDH.Text.StartsWith("8"))
                 {
                     num2 = tPfdata.yongliang;
                     if (tPfdata.yongliangDW == "Kg" || tPfdata.yongliangDW == "L")
                     {
                         num2 *= new Decimal(1000);
                     }
                 }
                 else
                 {
                     num2 = tPfdata.JLyongliang;
                     if (tPfdata.JLyongliangDW == "Kg" || tPfdata.JLyongliangDW == "L")
                     {
                         num2 *= new Decimal(1000);
                     }
                 }
                 if (num2 != (Decimal)this.dgvData.CurrentRow.Cells[this.colYL.Name].Value)
                 {
                     //dbpf.Dispose();
                     this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
                     this.TSsound.Play();
                     frmError frmError = new frmError("料单数据发生了改变!请再次查询!");
                     int      num3     = (int)frmError.ShowDialog((IWin32Window)this);
                     frmError.Close();
                 }
                 else
                 {
                     //dbpf.Dispose();
                     if (this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString() != "" && Convert.ToDecimal(this.dgvData.CurrentRow.Cells[this.colCL.Name].FormattedValue.ToString()) > new Decimal(0))
                     {
                         this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
                         this.TSsound.Play();
                         this.lblTS.Visible = false;
                         frmTS        frmTs        = new frmTS(this.CLrl, this.CLcheng, this.CLdeng, "该染料已称过,再称一次吗!!!", "“确认”再称一次", "“清除”取消称料", Keys.Back);
                         DialogResult dialogResult = frmTs.ShowDialog((IWin32Window)this);
                         frmTs.Close();
                         this.lblTS.Visible = true;
                         if (dialogResult != DialogResult.OK)
                         {
                             return;
                         }
                     }
                     if (this.CLcheng < 0)
                     {
                         this.TSsound.SoundLocation = Application.StartupPath + "\\Sound\\error.wav";
                         this.TSsound.Play();
                         frmError frmError = new frmError("无法找到合适的称,请核对!");
                         int      num3     = (int)frmError.ShowDialog((IWin32Window)this);
                         frmError.Close();
                     }
                     else
                     {
                         if (!this.plcCL.OpenDeng(this.CLdeng))
                         {
                             this.plcCL.OpenDeng(this.CLdeng);
                         }
                         this.staCL         = frmCL.enumSta.称料正在;
                         this.CLerrTPcount  = 0;
                         this.CLokCount     = 0;
                         this.CLallowKey    = false;
                         this.lblTPerr.Text = "";
                         this.CLzero();
                     }
                 }
             }
         }
     }
 }
示例#2
0
        private void this_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                this.txtSch.Text = this.txtSch.Text.Trim();
                if (this.txtSch.Text == "")
                {
                    frmError frmError = new frmError("无料单号,无法显示!!!");
                    int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                    frmError.Close();
                }
                else
                {
                    DataTable dataTable1 = new DataTable();
                    DataTable dataTable2 = new DataTable();
                    //using (SqlConnection sqlConnection = new SqlConnection(Settings.Default.DBconn))
                    {
                        //sqlConnection.Open();
                        //SqlCommand command = sqlConnection.CreateCommand();
                        //command.CommandTimeout = 300;

                        string CommandText = "select 1 from T_PFmain where danhao = '" + this.txtSch.Text + "' and sta = '已审核'";
                        //SqlDataReader sqlDataReader1 = command.ExecuteReader();
                        dataTable1 = db.Ado.GetDataTable(CommandText);
                        if (dataTable1.Rows.Count != 1)
                        {
                            //sqlDataReader1.Close();
                            //sqlDataReader1.Dispose();
                            //command.Dispose();
                            dataTable1.Dispose();
                            dataTable2.Dispose();
                            frmError frmError = new frmError("此料单单号不存在或者未审核!!!");
                            int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                            frmError.Close();
                            return;
                        }
                        string sql;
                        if (this.txtSch.Text.StartsWith("LD") || this.txtSch.Text.Length == 10 && this.txtSch.Text.StartsWith("8"))
                        {
                            sql = "select * from T_PFdata a where a.danhao = '" + this.txtSch.Text + "' and a.ranliao in(select item0 from T_Base where leibie = '染料名称') and a.yongliang > 0";
                        }
                        else
                        {
                            sql = "select * from T_PFdata a where a.danhao = '" + this.txtSch.Text + "' and a.ranliao in(select item0 from T_Base where leibie = '染料名称') and a.JLyongliang > 0";
                        }
                        //SqlDataReader sqlDataReader2 = command.ExecuteReader();
                        dataTable2 = db.Ado.GetDataTable(sql);
                        //sqlDataReader2.Close();
                        //sqlDataReader2.Dispose();
                        //command.Dispose();
                    }
                    if (dataTable2.Rows.Count == 0)
                    {
                        dataTable1.Dispose();
                        dataTable2.Dispose();
                        frmError frmError = new frmError("无法找到此料单用量数据!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                    }
                    else
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            else if (e.KeyCode == this.cancelKey)
            {
                this.DialogResult = DialogResult.Cancel;
            }
            else
            {
                if (e.KeyCode != Keys.Prior && e.KeyCode != Keys.Next)
                {
                    return;
                }
                if (this.lblTS.Text == "查询料单号(扫描输入)")
                {
                    this.lblTS.Text  = "查询料单号(键盘输入)";
                    this.txtSch.Text = "8" + DateTime.Today.ToString("yyMM");
                    this.txtSch.Select(this.txtSch.Text.Length, 0);
                    this.txtSch.ScrollToCaret();
                }
                else
                {
                    this.lblTS.Text  = "查询料单号(扫描输入)";
                    this.txtSch.Text = "";
                }
            }
        }
示例#3
0
文件: frmCL.cs 项目: tpc707494/C-Erp
        private bool cheng_plc_init()
        {
            //DBpf dbpf = new DBpf(Settings.Default.DBconn);
            //T_Base tBase = dbpf.T_Base.Where<T_Base>((Expression<Func<T_Base, bool>>)(a => a.leibie == PeiFang.BaseItem.leibie.enumLB.称料设置.ToString() && a.bianhao == this.jihao)).SingleOrDefault<T_Base>();
            T_Base tBase = db.Queryable <T_Base>()
                           .Where(a => a.leibie == "称料设置" && a.bianhao == this.jihao)
                           .First();

            //dbpf.Dispose();
            if (tBase == null)
            {
                frmError frmError = new frmError("无法找到本机台参数设置数据!!!");
                int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                frmError.Close();
                return(false);
            }
            for (int index = 0; index < 4; ++index)
            {
                string   str1;
                string   str2;
                string[] CLparaCheng = Settings.Default.CLparaCheng.Split('|');
                if (index == 0)
                {
                    str1 = tBase.item1;
                    str2 = CLparaCheng[0];
                }
                else if (index == 1)
                {
                    str1 = tBase.item2;
                    str2 = CLparaCheng[1];
                }
                else if (index == 2)
                {
                    str1 = tBase.item3;
                    str2 = CLparaCheng[2];
                }
                else
                {
                    str1 = tBase.item4;
                    str2 = CLparaCheng[3];
                }
                if (str1 != "" && str2 != "")
                {
                    string[] strArray1 = str1.Split(',');
                    string[] strArray2 = str2.Split(',');
                    if (strArray1.Length != 7)
                    {
                        frmError frmError = new frmError((index + 1).ToString() + " 号电子称参数设置错误!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                        return(false);
                    }
                    if (strArray2.Length != 8)
                    {
                        frmError frmError = new frmError((index + 1).ToString() + " 号电子称通讯设置错误!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                        return(false);
                    }
                    if (index > 0 && this.cheng[index - 1] == null)
                    {
                        frmError frmError = new frmError("请按小到大设置电子称!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                        return(false);
                    }
                    clsCheng clsCheng = new clsCheng();
                    try
                    {
                        StruChengPara struChengPara = new StruChengPara()
                        {
                            chengXH   = (enumCheng)Enum.Parse(typeof(enumCheng), strArray1[0]),
                            JingDu    = Convert.ToDecimal(strArray1[1]),
                            MaxCL     = Convert.ToDecimal(strArray1[2]),
                            WuCha     = Convert.ToDecimal(strArray1[3]),
                            WuChaPG   = strArray1[4],
                            OKci      = (int)Convert.ToInt16(strArray1[5]),
                            OKwd      = !(strArray1[6] == "0"),
                            zeroCi    = Convert.ToInt32(strArray2[4]),
                            zeroWD    = !(strArray2[5] == "False"),
                            scanSpeed = Convert.ToInt32(strArray2[6]),
                            zeroSpeed = Convert.ToInt32(strArray2[7])
                        };
                        clsCheng.chengPara = struChengPara;
                        clsCheng.PortName  = strArray2[0];
                        clsCheng.BaudRate  = Convert.ToInt32(strArray2[1]);
                        clsCheng.DataBits  = Convert.ToInt32(strArray2[2]);
                        clsCheng.Parity    = strArray2[3] == "Odd" ? Parity.Odd : (strArray2[3] == "Even" ? Parity.Even : Parity.None);
                        clsCheng.com_open();
                        this.cheng.Add(clsCheng);
                    }
                    catch
                    {
                        frmError frmError = new frmError("串口 " + (index + 1).ToString() + " 错误!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                        return(false);
                    }
                }
                else if (index == 0)
                {
                    frmError frmError = new frmError("串口 " + (index + 1).ToString() + " 参数设置错误!!!");
                    int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                    frmError.Close();
                    return(false);
                }
            }
            string[] strArray = Settings.Default.CLparaPLC.Split(',');
            if (strArray.Length != 5)
            {
                frmError frmError = new frmError("PLC 参数设置错误!!!");
                int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                frmError.Close();
                return(false);
            }
            try
            {
                this.plcCL.PortName      = strArray[0];
                this.plcCL.BaudRate      = Convert.ToInt32(strArray[1]);
                this.plcCL.DataBits      = Convert.ToInt32(strArray[2]);
                this.plcCL.Parity        = strArray[3] == "Odd" ? Parity.Odd : Parity.Even;
                this.plcCL.RWokReadDelay = Convert.ToInt32(strArray[4]);
                this.plcCL.com_open();
            }
            catch
            {
                frmError frmError = new frmError("PLC 打开错误!!!");
                int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                frmError.Close();
                return(false);
            }
            return(true);
        }
示例#4
0
        private void LblEnter_Click(object sender, EventArgs e)
        {
            this.txtSch.Text = this.txtSch.Text.Trim();
            if (this.txtSch.Text == "")
            {
                frmError frmError = new frmError("无料单号,无法显示!!!");
                int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                frmError.Close();
            }
            else
            {
                DataTable dataTable1 = new DataTable();
                DataTable dataTable2 = new DataTable();
                //using (SqlConnection sqlConnection = new SqlConnection(Settings.Default.DBconn))
                {
                    //sqlConnection.Open();
                    //SqlCommand command = sqlConnection.CreateCommand();
                    //command.CommandTimeout = 300;

                    string CommandText = "select 1 from T_PFmain where danhao = '" + this.txtSch.Text + "' and sta = '已审核'";
                    //SqlDataReader sqlDataReader1 = command.ExecuteReader();
                    dataTable1 = db.Ado.GetDataTable(CommandText);
                    if (dataTable1.Rows.Count != 1)
                    {
                        //sqlDataReader1.Close();
                        //sqlDataReader1.Dispose();
                        //command.Dispose();
                        dataTable1.Dispose();
                        dataTable2.Dispose();
                        frmError frmError = new frmError("此料单单号不存在或者未审核!!!");
                        int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                        frmError.Close();
                        return;
                    }
                    string sql;
                    if (this.txtSch.Text.StartsWith("LD") || this.txtSch.Text.Length == 10 && this.txtSch.Text.StartsWith("8"))
                    {
                        sql = "select * from T_PFdata a where a.danhao = '" + this.txtSch.Text + "' and a.ranliao in(select item0 from T_Base where leibie = '染料名称') and a.yongliang > 0";
                    }
                    else
                    {
                        sql = "select * from T_PFdata a where a.danhao = '" + this.txtSch.Text + "' and a.ranliao in(select item0 from T_Base where leibie = '染料名称') and a.JLyongliang > 0";
                    }
                    //SqlDataReader sqlDataReader2 = command.ExecuteReader();
                    dataTable2 = db.Ado.GetDataTable(sql);
                    //sqlDataReader2.Close();
                    //sqlDataReader2.Dispose();
                    //command.Dispose();
                }
                if (dataTable2.Rows.Count == 0)
                {
                    dataTable1.Dispose();
                    dataTable2.Dispose();
                    frmError frmError = new frmError("无法找到此料单用量数据!!!");
                    int      num      = (int)frmError.ShowDialog((IWin32Window)this);
                    frmError.Close();
                }
                else
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }