예제 #1
0
파일: Form1.cs 프로젝트: ericmuga/wscale
        private void Post_Click(object sender, EventArgs e)
        {
            //check if all necessary fields are there, and valid.
            //username

            //ReceiptNo
            if (ReceiptNo.Text == "")
            {
                MessageBox.Show("Invalid Receipt Number!");
                ReceiptNo.Focus();
            }
            if (SlapMark.Text == "")
            {
                MessageBox.Show("Invalid Slap Mark!");
                SlapMark.Focus();
            }
            if (CarcassType.Text == "")
            {
                MessageBox.Show("Invalid Carcass Type!");
                CarcassType.Focus();
            }

            if (MeatPercent.Text == "")
            {
                MessageBox.Show("Invalid Meat Percent!");
                MeatPercent.Focus();
            }

            using (SqlConnection conn = new SqlConnection(_connectionString))

            {
                CType = new string(CarcassType.Text.Take(5).ToArray());
                String q3 = "SELECT COUNT (ID) FROM [dbo].[SlaughterData] WHERE ReceiptNo ='" + ReceiptNo.Text + "'AND ItemNo ='" + CType + "'";
                using (SqlCommand cmd = new SqlCommand(q3, conn))
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "Error 5");
                        return;
                    }
                    try
                    {
                        Sqty = (int)cmd.ExecuteScalar();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "Error 6");
                        return;
                    }
                }

                conn.Close();
            }
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                //transcoding from from carcass code to livestock code to look up in the receipt ledger


                if (CType == "G0110")
                {
                    CType = "G0101";
                }
                if (CType == "G0111")
                {
                    CType = "G0102";
                }
                if (CType == "G0113")
                {
                    CType = "G0104";
                }



                String q = "SELECT sum(convert(int, ReceivedQty) )from dbo.Receipts where ReceiptNo ='" + ReceiptNo.Text + "'AND ItemNo='" + CType + "'";
                //MessageBox.Show(q);
                using (SqlCommand cmd = new SqlCommand(q, conn))
                {
                    try
                    {
                        conn.Open();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "Error7");
                        return;
                    }

                    try
                    {
                        Rqty = (int)cmd.ExecuteScalar();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + "Error3");
                        return;
                    }
                }
                conn.Close();
            }


            if (Rqty > Sqty)
            {
                using (SqlConnection conn = new SqlConnection(_connectionString))
                {
                    string Slap  = SlapMark.Text;
                    string VNo   = VendorNo.Text;
                    string VName = VendorName.Text;
                    string MPC   = MeatPercent.Text;
                    string CCode = ClassificationCode.Text;
                    string RNo   = ReceiptNo.Text;
                    CType = new string(CarcassType.Text.Take(5).ToArray());

                    //insert the record
                    String q5 = "INSERT INTO [dbo].[SlaughterData]([SlaughterTime],[UserID],[ReceiptNo],[ItemNo],[StockWeight],[MeatPercent],[Classification Code])" +
                                "VALUES ('" + DateTime.Now + "','"
                                + User.Text + "','"
                                + RNo + "','"
                                + CType + "','"
                                + NT + "','"
                                + MPC + "','"
                                + ClassificationCode.Text + "')";
                    using (SqlCommand cmd = new SqlCommand(q5, conn))
                    {
                        try
                        {
                            conn.Open();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message + "Error 8");
                            return;
                        }
                        try
                        {
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("Record Posted");
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message + "Error 11");
                        }
                        conn.Close();
                    }


                    if ((Rqty - Sqty) == 1)
                    {
                        if (CType == "G0110")
                        {
                            CType = "G0101";
                        }
                        if (CType == "G0111")
                        {
                            CType = "G0102";
                        }
                        if (CType == "G0113")
                        {
                            CType = "G0104";
                        }
                        //
                        String q6 = "UPDATE [dbo].[Receipts] SET [Slaughtered]='1'  WHERE ReceiptNo='" + RNo + "'AND ItemNo ='" + CType + "'";

                        using (SqlCommand cmd = new SqlCommand(q6, conn))
                        {
                            try
                            {
                                conn.Open();
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "Error 12");
                                return;
                            }
                            try
                            {
                                cmd.ExecuteNonQuery();
                                this.initComBo();
                                ReceiptNo.Text           = "";
                                SlapMark.Text            = "";
                                ReceiptNo.SelectedText   = "";
                                SlapMark.SelectedText    = "";
                                VendorName.Text          = "";
                                VendorNo.Text            = "";
                                CarcassType.Text         = "";
                                CarcassType.SelectedText = "";
                                MeatPercent.Text         = "";
                                ClassificationCode.Text  = "";
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "Error 10");
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("The record could not be posted. The slaughtered qty exceeds the received qty for that animal type");
                return;
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: ericmuga/wscale
        public Form1()
        {
            InitializeComponent();
            {
                if (!this.readWeight())
                {
                    //focus on ReceiptNo
                    ReceiptNo.Focus();
                }
                else
                {
                    Weight.Text.Remove(0);
                    Weight.ReadOnly = false;
                    Weight.Focus();
                }
                User.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                // Initialize the screen items
                ScaleID.Text     = Properties.Settings.Default.ScaleLID;
                CrateWeight.Text = Properties.Settings.Default.CrateWeight;
                // initialize comboboxes
                this.initComBo();
                try
                {
                    CR = Convert.ToDouble(CrateWeight.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Invalid Format in the crate weight");
                }
                catch (OverflowException)
                {
                    MessageBox.Show("The crate weight is too large");
                }

                try
                {
                    WT = Convert.ToDouble(Weight.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Invalid Format in the Scale reading");
                }
                catch (OverflowException)
                {
                    MessageBox.Show("The scale reading is too large");
                }
                NT = WT - CR;
                //rounding


                var result = NT - Math.Truncate(NT);
                if (result > 0.54)
                {
                    NT = Math.Ceiling(NT);
                }
                else
                {
                    NT = Math.Floor(NT);
                }

                NetWeight.Text = Convert.ToString(NT);
            }
        }