Example #1
0
        private void Create_bom_btn_Click(object sender, EventArgs e)
        {
            setPoNum();
            try
            {
                string query = "insert into bom( postedUser, pro_id) values (@user, @proId);";
                List <MySqlParameter> paramList = new List <MySqlParameter>();
                paramList.Clear();
                paramList.Add(new MySqlParameter("@user", GlobalLoginData.username));
                paramList.Add(new MySqlParameter("@proId", poText.Text));

                int rowsAffected = DatabaseHandler.insertOrDeleteRow(query, paramList);

                if (rowsAffected != 0)
                {
                    //MessageBox.Show("BOM Created Successfully!");
                }
                else
                {
                    MessageBox.Show("Error Occured! Please check input details!");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error Occured! Please check input details!");
            }



            int i = dataGridView2.Rows.Count;

            Console.WriteLine("Special i Value: " + i);
            string itemid;
            string qty;
            string bomId = bom_lbl.Text;

            for (int row = 0; row < i - 1; row++)
            {
                itemid = dataGridView2.Rows[row].Cells[1].Value.ToString();
                qty    = dataGridView2.Rows[row].Cells[3].Value.ToString();

                string querry = "SELECT material_id as 'material_id', quantity as 'quantity' FROM composition WHERE item_id= '" + itemid + "'";

                DatabaseHandler.populatebomDataGridView(querry, dataGridView1, qty);
            }



            int j = dataGridView1.Rows.Count;

            Console.WriteLine("Special j Value: " + j);

            int temp = 0;

            for (int row = 0; row < j - 1; row++)
            {
                itemid = dataGridView1.Rows[row].Cells[0].Value.ToString();
                qty    = dataGridView1.Rows[row].Cells[1].Value.ToString();
                Console.WriteLine(itemid + "   " + qty);
                try
                {
                    string query = "INSERT INTO bom_item VALUES (@material_id, @bom_id, @qty)";
                    List <MySqlParameter> paramList = new List <MySqlParameter>();
                    paramList.Add(new MySqlParameter("@material_id", itemid));
                    paramList.Add(new MySqlParameter("@bom_id", bomId));
                    paramList.Add(new MySqlParameter("@qty", qty));

                    int rowsAffected = DatabaseHandler.insertOrDeleteRow(query, paramList);

                    if (rowsAffected != 0)
                    {
                        //  MessageBox.Show("BOM Created Successfully!");
                        temp++;
                    }
                    else
                    {
                        MessageBox.Show("Error Occured! BOM-material Link Broken!");
                        return;
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Error Occured!");
                }
            }

            data = GetDataTableFromDGV(dataGridView1);
            if (temp != 0)
            {
                MessageBox.Show("BOM Created Successfully!");
            }
        }