private void pictureBox2_Click(object sender, EventArgs e)
 {
     if (Application.OpenForms["AdvancedSearch"] == null)
     {
         TyreSection adv = new TyreSection();
         adv.MdiParent = this;
         adv.Size = new System.Drawing.Size(1100, 670);
         adv.Location = new System.Drawing.Point(5, 5);
         adv.Show();
     }
 }
Esempio n. 2
0
        private void btn_reduce_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to reduce stock?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int catagory_id = vehical_category_data.get_catagory_id();
                bool check;
                int a;
                check = int.TryParse(txt_qty.Text, out a);

                if (txt_qty.Text == "")
                {
                    MessageBox.Show("Enter qty!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else if (!check)
                {
                    MessageBox.Show("Enter correct qty!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txt_qty.Text = "";

                }
                else if (Convert.ToInt32(txt_qty.Text) < 0)
                {
                    MessageBox.Show("Qty can not less than Zero!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txt_qty.Text = "";
                }

                else
                {
                    int cat_id = vehical_category_data.get_catagory_id();

                    string q0 = "SELECT * FROM add_vehical_tyre WHERE t_stok_id =" + cat_id + "";
                    DataSet ds_qty_table = middle_access.db_access.SelectData(q0);
                    if (ds_qty_table == null)
                    {
                        MessageBox.Show("Can not reduce!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);//show message box with ok button

                    }
                    else
                    {
                        DataRow row_catagory_id = ds_qty_table.Tables[0].Rows[0];
                        int available_qty = Convert.ToInt32(row_catagory_id.ItemArray.GetValue(9).ToString());

                        if (available_qty < Convert.ToInt32(txt_qty.Text))
                        {

                            MessageBox.Show("Available stock is insufficient!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);//show message box with ok button
                            txt_qty.Text = "";
                        }
                        else
                        {
                            int new_qty = available_qty - Convert.ToInt32(txt_qty.Text);

                            string q = "SELECT * FROM qty WHERE category_id = " + catagory_id + "";
                            DataSet ds_catagory_id = middle_access.db_access.SelectData(q);

                            string date = DateTime.Today.Date.ToString("yyyy-MM-dd");
                            string time = DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();
                            string action = "-";

                            string q1 = "INSERT INTO qty VALUES(" + cat_id + "," + Convert.ToInt32(lbl_Aq.Text) + ",'" + action + "'," + Convert.ToInt32(txt_qty.Text) + ", '" + date + "','" + time + "')";

                            bool status = middle_access.db_access.InsertData(q1);
                            if (status == true)
                            {
                                string q2 = "UPDATE add_vehical_tyre SET qty = " + new_qty + "  WHERE t_stok_id = " + cat_id + " ";
                                middle_access.db_access.UpdateData(q2);
                                MessageBox.Show("OK!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);//show message box with ok button
                                TyreSection s = new TyreSection();
                                s.set_total_qty();
                                if (new_qty == 0)
                                {
                                    lbl_Aq.ForeColor = Color.Red;
                                }

                                lbl_Aq.Text = new_qty.ToString();
                                txt_qty.Text = "";
                            }
                            else
                            {
                                MessageBox.Show("Error!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                        }
                    }
                }

            }
        }