Esempio n. 1
0
        private void btnUpdDate_Click(object sender, EventArgs e)
        {
            dtpDate = null;
            int ri = dgvRet.CurrentRow.Index;

            if (ri >= 0)
            {
                string id     = dgvRet.Rows[ri].Cells[3].Value.ToString();
                string detdet = dgvRet.Rows[ri].Cells[6].Value.ToString();
                if (dtpDate != null || dtpDate != "" && counter == 0 && detdet == "")
                {
                    addDate det = new addDate();
                    det.ret    = this;
                    det.offSet = 2;
                    det.ShowDialog();
                    if (user_type == 4 && dtpDate != null)
                    {
                        string upd = "UPDATE po_return SET date_rec = '" + dtpDate + "', sup_id = '" + user_id + "' WHERE return_id = '" + id + "'";
                        conn.Open();
                        MySqlCommand comm = new MySqlCommand(upd, conn);
                        comm.ExecuteNonQuery();
                        conn.Close();
                        MessageBox.Show("Successfully updated the Return Date!", "Successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    if (user_type == 1 && dtpDate != null)
                    {
                        string upd = "UPDATE po_return SET return_date = '" + dtpDate + "' WHERE return_id = '" + id + "'";
                        conn.Open();
                        MySqlCommand comm = new MySqlCommand(upd, conn);
                        comm.ExecuteNonQuery();
                        conn.Close();
                        MessageBox.Show("Successfully updated the Return Date!", "Successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    counter = 0;
                    showReturnStaff();
                }
                else
                {
                    MessageBox.Show("Already Received cannot change the return date!", "Already Received!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    btnUpdDate.Enabled   = false;
                    btnUpdDate.BackColor = Color.LightGray;
                    btnUpdDate.ForeColor = Color.White;
                }
            }
        }
Esempio n. 2
0
 private void btnViewRet_Click(object sender, EventArgs e)
 {
     if (offSet == 0)
     {
         int ri = dgvRet.CurrentRow.Index;
         if (ri >= 0)
         {
             lblRetId.Text = dgvRet.Rows[ri].Cells[0].Value.ToString();
             if (dgvRet.Rows[ri].Cells[5].Value.ToString() != "" && user_type == 4)
             {
                 btnViewRet.Text = "Deliver";
             }
             else if (user_type == 1)
             {
                 btnViewRet.Hide();
             }
             else
             {
                 btnViewRet.Text = "Receive";
             }
             showLine(lblRetId.Text);
         }
     }
     else if (offSet == 1)
     {
         if (btnViewRet.Text == "Receive")
         {
             conn.Open();
             string           ch   = "SELECT sup_id FROM po_return WHERE ret_id = '" + lblRetId.Text + "'";
             MySqlCommand     comm = new MySqlCommand(ch, conn);
             MySqlDataAdapter adp  = new MySqlDataAdapter(comm);
             comm.ExecuteNonQuery();
             DataTable dt = new DataTable();
             adp.Fill(dt);
             if (dt.Rows[0][0].ToString() == "")
             {
                 string upd = "UPDATE po_return SET date_rec = '" + DateTime.Now.ToString("yyyy-MM-dd") + "', sup_id = '" + user_id + "' WHERE ret_id = '" + lblRetId.Text + "'";
                 comm = new MySqlCommand(upd, conn);
                 comm.ExecuteNonQuery();
                 MessageBox.Show("Successfully Received all Item/s.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 btnViewRet.Text = "Deliver";
             }
             else
             {
                 MessageBox.Show("You have Already Received this Returned Items.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             conn.Close();
         }
         else if (btnViewRet.Text == "Deliver")
         {
             conn.Open();
             string           ch   = "SELECT max(del_ret_id), MAX(dr) FROM po_del_ret";
             MySqlCommand     comm = new MySqlCommand(ch, conn);
             MySqlDataAdapter adp  = new MySqlDataAdapter(comm);
             comm.ExecuteNonQuery();
             DataTable dt = new DataTable();
             adp.Fill(dt);
             int dr         = 1;
             int del_ret_id = 0;
             if (dt.Rows[0][0].ToString() == "" && dt.Rows[0][1].ToString() == "")
             {
                 dr         = 1;
                 del_ret_id = 1;
             }
             else
             {
                 dr         = int.Parse(dt.Rows[0][0].ToString()) + 1;
                 del_ret_id = int.Parse(dt.Rows[0][1].ToString());
             }
             addDate add = new addDate();
             add.offSet = 3;
             add.poRet  = this;
             add.ShowDialog();
             string ins = "INSERT INTO po_del_ret VALUES(NULL, '" + det + "', '" + user_id + "', '" + dr + "', NULL, NULL)";
             comm = new MySqlCommand(ins, conn);
             comm.ExecuteNonQuery();
             string           select = "SELECT max(del_ret_id) FROM po_del_ret";
             MySqlCommand     comm2  = new MySqlCommand(select, conn);
             MySqlDataAdapter adp2   = new MySqlDataAdapter(comm2);
             comm2.ExecuteNonQuery();
             DataTable dt2 = new DataTable();
             adp2.Fill(dt2);
             int co = 0;
             for (int i = 0; i < dgvRet.Rows.Count; i++)
             {
                 if (dgvRet.Rows[i].Cells["txt"].Value.ToString() != "0" && int.Parse(dgvRet.Rows[i].Cells["txt"].Value.ToString()) > 0)
                 {
                     ins  = "INSERT INTO po_del_ret_line VALUES(NULL, '" + dt2.Rows[0][0].ToString() + "', '" + dgvRet.Rows[i].Cells[0].Value.ToString() + "', '" + dgvRet.Rows[i].Cells["item_id"].Value.ToString() + "' ,'" + dgvRet.Rows[i].Cells["txt"].Value.ToString() + "')";
                     comm = new MySqlCommand(ins, conn);
                     comm.ExecuteNonQuery();
                     int excess = int.Parse(dgvRet.Rows[i].Cells[5].Value.ToString()) - int.Parse(dgvRet.Rows[i].Cells["txt"].Value.ToString());
                     if (excess < 0)
                     {
                         excess = 0;
                     }
                     ins  = "UPDATE po_return_line SET qtyRem = '" + excess + "' WHERE ret_line_id = '" + dgvRet.Rows[i].Cells[0].Value.ToString() + "'";
                     comm = new MySqlCommand(ins, conn);
                     comm.ExecuteNonQuery();
                     co++;
                 }
             }
             if (co > 0)
             {
                 MessageBox.Show("Successfully set the delivery date!");
             }
             conn.Close();
         }
     }
 }
        private void btnRet_Click(object sender, EventArgs e)
        {
            int c = 0;

            for (int i = 0; i < dgvDel.Rows.Count; i++)
            {
                if (int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString()) != 0 || dgvDel.Rows[i].Cells["txt"].Value.ToString() == "" && dgvDel.Rows[i].Cells["qtyRet"].Value.ToString() != "0")
                {
                    c++;
                }
            }
            if (c > 0)
            {
                addDate add = new addDate();
                add.offSet = 4;
                add.delRet = this;
                add.ShowDialog();
                conn.Open();
                string           set = "SELECT max(ret_id) FROM po_return";
                MySqlCommand     com = new MySqlCommand(set, conn);
                MySqlDataAdapter ad  = new MySqlDataAdapter(com);
                com.ExecuteNonQuery();
                DataTable d = new DataTable();
                ad.Fill(d);
                int rn = 0;
                if (d.Rows[0][0].ToString() == null || d.Rows[0][0].ToString() == "")
                {
                    rn = int.Parse(DateTime.Now.ToString("yyyyMMdd")) + 1;
                }
                else
                {
                    rn = int.Parse(DateTime.Now.ToString("yyyyMMdd")) + int.Parse(d.Rows[0][0].ToString());
                }
                conn.Close();
                string ins = "INSERT INTO po_return VALUES(NULL, '" + lblPO_del_id.Text + "', '" + det + "', '" + user_id + "', null, null, '" + rn + "');";
                conn.Open();
                MySqlCommand comm = new MySqlCommand(ins, conn);
                comm.ExecuteNonQuery();
                string sel = "SELECT max(ret_id), rn FROM po_return";
                comm = new MySqlCommand(sel, conn);
                MySqlDataAdapter adp = new MySqlDataAdapter(comm);
                comm.ExecuteNonQuery();
                DataTable dt  = new DataTable();
                DataTable drn = new DataTable();
                adp.Fill(dt);
                adp.Fill(drn);
                int o = 0;
                for (int i = 0; i < dgvDel.Rows.Count; i++)
                {
                    if (int.Parse(dgvDel.Rows[i].Cells["qtyRet"].Value.ToString()) - int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString()) < 0)
                    {
                        dgvDel.Rows[i].Cells["txt"].Value = dgvDel.Rows[i].Cells["qtyRet"].Value.ToString();
                        o++;
                    }
                    if (int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString()) != 0 || dgvDel.Rows[i].Cells["txt"].Value.ToString() != "" && int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString()) > 0)
                    {
                        ins  = "INSERT INTO po_return_line VALUES(NULL, '" + dt.Rows[0][0].ToString() + "', '" + dgvDel.Rows[i].Cells["po_del_line_id"].Value.ToString() + "', '" + dgvDel.Rows[i].Cells["item_id"].Value.ToString() + "', '" + dgvDel.Rows[i].Cells["txt"].Value.ToString() + "', '" + dgvDel.Rows[i].Cells["txt"].Value.ToString() + "')";
                        comm = new MySqlCommand(ins, conn);
                        comm.ExecuteNonQuery();
                        sel  = "SELECT item_id, qty FROM inventory WHERE des = '" + dgvDel.Rows[i].Cells[19].Value.ToString() + "'";
                        comm = new MySqlCommand(sel, conn);
                        adp  = new MySqlDataAdapter(comm);
                        comm.ExecuteNonQuery();
                        DataTable dtr = new DataTable();
                        adp.Fill(dtr);
                        int    excess = int.Parse(dtr.Rows[0][1].ToString()) - int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString());
                        string upd    = "UPDATE inventory set qty = '" + excess + "' WHERE item_id = '" + dtr.Rows[0][0].ToString() + "'";
                        comm = new MySqlCommand(upd, conn);
                        comm.ExecuteNonQuery();
                        int ret = int.Parse(dgvDel.Rows[i].Cells["qtyRet"].Value.ToString()) - int.Parse(dgvDel.Rows[i].Cells["txt"].Value.ToString());
                        upd  = "UPDATE po_del_line set qtyRet = '" + ret + "' WHERE po_del_line_id = '" + dgvDel.Rows[i].Cells["po_del_line_id"].Value.ToString() + "'";
                        comm = new MySqlCommand(upd, conn);
                        comm.ExecuteNonQuery();
                        ins  = "INSERT INTO stock_out_ret VALUES(NULL, '" + dtr.Rows[0][0].ToString() + "', '" + det + "', '" + dgvDel.Rows[i].Cells["txt"].Value.ToString() + "', '" + user_id + "', '" + drn.Rows[0][0].ToString() + "')";
                        comm = new MySqlCommand(ins, conn);
                        comm.ExecuteNonQuery();
                    }
                }
                if (o > 0)
                {
                    MessageBox.Show("Some of the items returned exceed more than the returnables so it automatically set it to the highest possible returns.", "", MessageBoxButtons.OK);
                }
                MessageBox.Show("Successfully Returned!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                conn.Close();
                showDelLineSupRec(int.Parse(lblPO_del_id.Text));
            }
            else
            {
                MessageBox.Show("You must return more than 0 items!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 private void btnView_Click(object sender, EventArgs e)
 {
     if (offset == 1 || offset == 0)
     {
         if (dgvDel.Rows.Count >= 1)
         {
             int ri = dgvDel.CurrentRow.Index;
             if (ri >= 0)
             {
                 int id = int.Parse(dgvDel.Rows[ri].Cells["po_del_id"].Value.ToString());
                 if (user_type == 5 || user_type == 1 && user_type != 4)
                 {
                     showDelLineSupRec(id);
                     btnView.Text = "Receive Items";
                     offset       = 2;
                 }
                 else if (user_type == 4 && btnView.Text == "View")
                 {
                     btnView.Hide();
                     showDelLineSup(id);
                     offset = 1;
                 }
                 lblPO_del_id.Text = id.ToString();
             }
         }
     }
     else if (user_type == 5 || user_type == 1 && offset == 2)
     {
         int c = 0;
         for (int i = 0; i < dgvDel.Rows.Count; i++)
         {
             int ri = i;
             if (ri >= 0)
             {
                 conn.Open();
                 string           ch    = "SELECT date_rec, date_del FROM po_del_line pdl, po_del pd WHERE po_del_line_id = '" + dgvDel.Rows[ri].Cells[0].Value.ToString() + "' AND pd.po_del_id = pdl.po_del_id";
                 MySqlCommand     comm2 = new MySqlCommand(ch, conn);
                 MySqlDataAdapter adp2  = new MySqlDataAdapter(comm2);
                 comm2.ExecuteNonQuery();
                 DataTable dt2 = new DataTable();
                 adp2.Fill(dt2);
                 conn.Close();
                 if (dt2.Rows[0][0].ToString() == "")
                 {
                     if (dgvDel.Rows[ri].Cells[5].Value.ToString() == "")
                     {
                         /*int id = int.Parse(dgvDel.Rows[ri].Cells[0].Value.ToString());
                          * addQuantity add = new addQuantity();
                          * add.offSet = 4;
                          * add.limit = int.Parse(dgvDel.Rows[ri].Cells[8].Value.ToString());
                          * add.rec = this;
                          * add.ShowDialog();*/
                         conn.Open();
                         string checkDate = "SELECT DATEDIFF('" + DateTime.Parse(dt2.Rows[0][1].ToString()).ToString("yyyy-MM-dd") + "', '" + lbldate.Text + "')";
                         comm2 = new MySqlCommand(checkDate, conn);
                         adp2  = new MySqlDataAdapter(comm2);
                         comm2.ExecuteNonQuery();
                         DataTable dt3 = new DataTable();
                         adp2.Fill(dt3);
                         conn.Close();
                         quant = int.Parse(dgvDel.Rows[i].Cells["qtyDel"].Value.ToString());
                         if (int.Parse(dt3.Rows[0][0].ToString()) <= 0 || dt3.Rows[0][0].ToString() != "")
                         {
                             if (quant > 0)
                             {
                                 string upd = "UPDATE po_del_line SET qty_rec = '" + quant + "', date_rec ='" + DateTime.Today.ToString("yyyy-MM-dd") + "', prof_id = '" + user_id + "' WHERE po_del_line_id = '" + dgvDel.Rows[ri].Cells[0].Value.ToString() + "'";
                                 conn.Open();
                                 MySqlCommand comm = new MySqlCommand(upd, conn);
                                 comm.ExecuteNonQuery();
                                 string ins = "INSERT INTO stock_in VALUES(NULL, '" + dgvDel.Rows[ri].Cells[3].Value.ToString() + "', '" + DateTime.Now.ToString("yyyy-MM-dd") + "', '" + quant + "', '" + user_id + "', '" + dgvDel.Rows[ri].Cells[20].Value.ToString() + "')";
                                 comm = new MySqlCommand(ins, conn);
                                 comm.ExecuteNonQuery();
                                 string ser = "SELECT item_id, qty FROM inventory WHERE des = '" + dgvDel.Rows[ri].Cells[18].Value.ToString() + "'";
                                 comm = new MySqlCommand(ser, conn);
                                 MySqlDataAdapter adp = new MySqlDataAdapter(comm);
                                 comm.ExecuteNonQuery();
                                 DataTable dt = new DataTable();
                                 adp.Fill(dt);
                                 if (dt.Rows.Count == 1)
                                 {
                                     int qt = int.Parse(dt.Rows[0][1].ToString()) + int.Parse(dgvDel.Rows[ri].Cells[8].Value.ToString());
                                     upd  = "UPDATE inventory SET qty = '" + qt + "' WHERE item_id = '" + dt.Rows[0][0].ToString() + "'";
                                     comm = new MySqlCommand(upd, conn);
                                     comm.ExecuteNonQuery();
                                 }
                                 else
                                 {
                                     ins  = "INSERT INTO inventory VALUES(NULL, '" + dgvDel.Rows[ri].Cells[19].Value.ToString() + "','" + quant + "', NULL)";
                                     comm = new MySqlCommand(ins, conn);
                                     comm.ExecuteNonQuery();
                                 }
                                 conn.Close();
                                 offset = 1;
                                 if (quant < int.Parse(dgvDel.Rows[ri].Cells[8].Value.ToString()))
                                 {
                                     int          excess = int.Parse(dgvDel.Rows[ri].Cells[8].Value.ToString()) - quant;
                                     DialogResult res    = MessageBox.Show("Do you want to set the date for the damaged items now?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                                     if (DialogResult.OK == res)
                                     {
                                         addDate det = new addDate();
                                         det.del    = this;
                                         det.offSet = 1;
                                         det.ShowDialog();
                                         ins = "INSERT INTO po_return VALUES(NULL, '" + dgvDel.Rows[ri].Cells[0].Value.ToString() + "', '" + dtpDate + "', '" + user_id + "', NULL, NULL, NULL, '" + excess + "')";
                                     }
                                     else
                                     {
                                         ins = "INSERT INTO po_return VALUES(NULL, '" + dgvDel.Rows[ri].Cells[0].Value.ToString() + "', NULL, NULL, NULL, NULL , NULL, '" + excess + "')";
                                     }
                                     int re = int.Parse(dgvDel.Rows[ri].Cells[9].Value.ToString()) - quant;
                                     conn.Open();
                                     comm = new MySqlCommand(ins, conn);
                                     comm.ExecuteNonQuery();
                                     conn.Close();
                                     MessageBox.Show("Incomplete Items Received Successfully! You can update the return date from the Return Form from the Dashboard.", "Successfully Set!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 }
                             }
                             else
                             {
                                 MessageBox.Show("You must Receive more than 0 items!", "");
                             }
                         }
                         else
                         {
                             MessageBox.Show("You cannot Receive Items Now! Please see Date Delivery Before receiving", "");
                         }
                         offset = 1;
                     }
                 }
                 else
                 {
                     c++;
                 }
             }
             else
             {
                 MessageBox.Show("Item cannot be found!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         if (c > 0)
         {
             MessageBox.Show("Already Received! Cannot Receive again", "Please Choose another Item!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             MessageBox.Show("Received All Items Successfully!", "");
         }
         if (user_type == 5 || user_type == 1 && user_type != 4)
         {
             dgvDel.DataSource = null;
             dgvDel.Rows.Clear();
             //showPurchDelStaff();
             btnView.Text = "View";
             btnRet.Hide();
             offset = 0;
         }
         else if (user_type == 4 && btnView.Text == "View")
         {
             showDelLineSup(int.Parse(lblPO_del_id.Text));
         }
     }
 }