Beispiel #1
0
        private void mtadd_Click_1(object sender, EventArgs e)
        {
            int     flag = 1, error = 0;
            String  date   = txtdate.Text;
            String  status = txtstatus.Text;
            DBSales ds     = new DBSales();

            if (txtqty.Text.Length == 0 && txtprice.Text.Length == 0 && txtstatus.Text.Length == 0)
            {
                MessageBox.Show("Check if all the fields are filled", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = 1;
            }
            if (txtprice.Text.Any(Char.IsLetter))
            {
                MessageBox.Show("Price cannot contain letters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                error = 1;
            }
            if (txtqty.Text.Any(Char.IsLetter))
            {
                error = 1;
                MessageBox.Show("Quantity cannot contain letters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (cmbitemname.SelectedIndex == 0)
            {
                error = 1;
                MessageBox.Show("Please select an Item Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (error == 1)
            {
                MessageBox.Show("Check if all the fields are filled correctly", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            else
            {
                int so_no = ds.setSalesOrder(date, status, count_tot, count_qty, u_id, no);
                DBSales_Item_reference S_I_ref = new DBSales_Item_reference();
                foreach (DataGridViewRow Datarow in dataGridView1.Rows)
                {
                    if (Datarow.Cells[0].Value != null && Datarow.Cells[1].Value != null && Datarow.Cells[2].Value != null)
                    {
                        String itemName = dataGridView1.CurrentRow.Cells["itemName"].Value.ToString();
                        int    itemqty  = Convert.ToInt32(dataGridView1.CurrentRow.Cells["itemQty"].Value);
                        int    itemtot  = Convert.ToInt32(dataGridView1.CurrentRow.Cells["itemPrice"].Value);

                        DBItem di     = new DBItem();
                        int    itemno = di.getItemNo(itemName);
                        S_I_ref.setReference(so_no, itemno, itemqty, itemtot);
                        di.updateQty(itemno, itemqty, txtdate.Text.ToString(), flag);
                    }
                }
            }
        }
        private void cmbitemname_SelectedIndexChanged(object sender, EventArgs e)
        {
            int Qty = 0;
            DBSales_Item_reference sal = new DBSales_Item_reference();
            String itemname            = cmbitemname.SelectedItem.ToString();
            DBItem i      = new DBItem();
            int    itemno = i.getItemNo(itemname);

            DR = sal.getQty(itemno);
            while (DR.Read())
            {
                Qty = Convert.ToInt32(DR[0]);
            }

            numQty.Maximum = Qty;
            numQty.Value   = Qty;
        }
        private void cmbsorder_SelectedIndexChanged(object sender, EventArgs e)
        {
            int so_no = Convert.ToInt32(cmbsorder.SelectedItem);
            DBSales_Item_reference si = new DBSales_Item_reference();

            DR = si.getItems(so_no);
            int    itemno;
            String itemname = "";

            while (DR.Read())
            {
                itemno = Convert.ToInt32(DR[0]);
                DBItem i = new DBItem();
                DR2 = i.getName(itemno);
                while (DR2.Read())
                {
                    itemname = DR2[0].ToString();
                }
                cmbitemname.Items.Add(itemname);
            }
        }