コード例 #1
0
        private void btn_EdittoDGV_Click(object sender, EventArgs e)
        {
            Supply_Permission_Product spp = new Supply_Permission_Product();

            spp.Per_Id  = Convert.ToInt32(dgv_Products.CurrentRow.Cells["PermissionId"].Value);
            spp.Prod_Id = Convert.ToInt32(dgv_Products.CurrentRow.Cells["ProductId"].Value);
            spp         = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id && a.Prod_Id == spp.Prod_Id).FirstOrDefault();
            if (txt_Quantity.Text != string.Empty && txt_PD.Text != string.Empty && txt_ED.Text != string.Empty)
            {
                spp.Prod_Id         = cb_Products.SelectedIndex;
                spp.Prod_Name       = cb_Products.Text;
                spp.Prod_Quantity   = int.Parse(txt_Quantity.Text);
                spp.Production_Date = DateTime.Parse(txt_PD.Text);
                spp.Expiration_Date = DateTime.Parse(txt_ED.Text);
                MessageBox.Show("product is updated");
                dgv_Products.DataSource = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id).ToList();
                txt_Quantity.Text       = string.Empty;
                txt_PD.Text             = string.Empty;
                txt_ED.Text             = string.Empty;
                btn_AddtoDGV.Enabled    = true;
            }
            else
            {
                MessageBox.Show("please complete missing fields in product form");
            }
        }
コード例 #2
0
 /// <summary>
 /// list product in permission operation inside supply permission tab page
 /// </summary>
 private void btn_AddtoDGV_Click(object sender, EventArgs e)
 {
     if (txt_Quantity.Text != string.Empty && txt_PD.Text != string.Empty && txt_ED.Text != string.Empty)
     {
         Supply_Permission_Product spp = new Supply_Permission_Product()
         {
             Per_Id          = int.Parse(txt_SPid.Text),
             Prod_Id         = cb_Products.SelectedIndex,
             Prod_Name       = cb_Products.Text,
             Prod_Quantity   = int.Parse(txt_Quantity.Text),
             Production_Date = DateTime.Parse(txt_PD.Text),
             Expiration_Date = DateTime.Parse(txt_ED.Text)
         };
         db.Supply_Permission_Product.Add(spp);
         db.SaveChanges();
         MessageBox.Show("product added successfully");
         dgv_Products.DataSource = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id).ToList();
         txt_Quantity.Text       = string.Empty;
         txt_PD.Text             = string.Empty;
         txt_ED.Text             = string.Empty;
     }
     else
     {
         MessageBox.Show("please complete missing fields in product form");
     }
 }
コード例 #3
0
        private void btn_DeletefromDGV_Click(object sender, EventArgs e)
        {
            Supply_Permission_Product spp = new Supply_Permission_Product();

            spp.Per_Id  = Convert.ToInt32(dgv_Products.CurrentRow.Cells["PermissionId"].Value);
            spp.Prod_Id = Convert.ToInt32(dgv_Products.CurrentRow.Cells["ProductId"].Value);
            spp         = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id && a.Prod_Id == spp.Prod_Id).FirstOrDefault();
            db.Supply_Permission_Product.Remove(spp);
            db.SaveChanges();
            MessageBox.Show("product deleted sucessfuly");
            dgv_Products.DataSource = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id && a.Prod_Id == spp.Prod_Id).ToList();
            txt_Quantity.Text       = string.Empty;
            txt_PD.Text             = string.Empty;
            txt_ED.Text             = string.Empty;
            btn_AddtoDGV.Enabled    = true;
        }
コード例 #4
0
 // edit selected row by double click event
 private void dgv_Products_DoubleClick(object sender, EventArgs e)
 {
     if (dgv_Products.CurrentRow.Index != -1)
     {
         Supply_Permission_Product spp = new Supply_Permission_Product();
         spp.Per_Id                = Convert.ToInt32(dgv_Products.CurrentRow.Cells["PermissionId"].Value);
         spp.Prod_Id               = Convert.ToInt32(dgv_Products.CurrentRow.Cells["ProductId"].Value);
         spp                       = db.Supply_Permission_Product.Where(a => a.Per_Id == spp.Per_Id && a.Prod_Id == spp.Prod_Id).FirstOrDefault();
         txt_Quantity.Text         = spp.Prod_Quantity.ToString();
         txt_PD.Text               = spp.Production_Date.ToString();
         txt_ED.Text               = spp.Expiration_Date.ToString();
         cb_Products.SelectedIndex = spp.Prod_Id;
         btn_EdittoDGV.Text        = "Update";
         btn_AddtoDGV.Enabled      = false;
     }
 }