Пример #1
0
 protected void rgProdType_UpdateCommand(object sender, GridCommandEventArgs e)
 {
     using (var context = new cathlabEntities())
     {
         int         ID = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"].ToString());
         ProductType pt = context.ProductTypes.Find(ID);
         pt.Type = (e.Item.FindControl("tbType") as RadTextBox).Text;
         context.SaveChanges();
     }
 }
Пример #2
0
 protected void btnInsertProduct_Click(object sender, EventArgs e)
 {
     using (var context = new cathlabEntities())
     {
         Product prod = new Product();
         prod.PartNumber     = txtPartNum.Text;
         prod.LotNumber      = (txtLotNumber.Text != null) ? int.Parse(txtLotNumber.Text) : -1;
         prod.ExpirationDate = rdpExpiration.SelectedDate;
         prod.LocationID     = int.Parse(lbxLoc.SelectedValue);
         context.Products.Add(prod);
         context.SaveChanges();
     }
 }
Пример #3
0
 protected void rgPartNumbers_UpdateCommand(object sender, GridCommandEventArgs e)
 {
     if (e.CommandName == "Update")
     {
         using (var context = new cathlabEntities())
         {
             int        PNum = int.Parse(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["PartNum"].ToString());
             PartNumber pn   = context.PartNumbers.Find(PNum);
             pn.NameSize = (e.Item.FindControl("tbNameSize") as RadTextBox).Text;
             pn.Cost     = int.Parse((e.Item.FindControl("tbCost") as RadTextBox).Text);
             pn.Par      = int.Parse((e.Item.FindControl("tbPar") as RadTextBox).Text);
             context.SaveChanges();
         }
     }
 }
Пример #4
0
        protected void rgManufacturers_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = (GridDataItem)e.Item;
            int          ID   = (int)item.GetDataKeyValue("ID");

            using (var context = new cathlabEntities())
            {
                Manufacturer m = context.Manufacturers.Find(ID);
                try
                {
                    context.Manufacturers.Remove(m);
                    context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    rnLabel.Text = "ERROR! Can't delete manufacturer. Products in database rely on this entry.";
                    RadNotification.Show();
                }
            }
        }
Пример #5
0
        protected void rgPartNumbers_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item    = (GridDataItem)e.Item;
            string       PartNum = item.GetDataKeyValue("PartNum").ToString();

            using (var context = new cathlabEntities())
            {
                PartNumber pn = context.PartNumbers.Find(PartNum);
                try
                {
                    context.PartNumbers.Remove(pn);
                    context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    rnLabel.Text = "ERROR! Cannot delete, there are products<br/> in the database of that part number.";
                    RadNotification.Show();
                }
            }
        }
Пример #6
0
        protected void rgProdType_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = (GridDataItem)e.Item;
            int          ID   = (int)item.GetDataKeyValue("ID");

            using (var context = new cathlabEntities())
            {
                ProductType pt   = context.ProductTypes.Find(ID);
                var         temp = (from prod in context.Products
                                    where prod.PartNumber1.ProductTypeID == pt.ID
                                    select prod).FirstOrDefault();

                if (temp == null)
                {
                    context.ProductTypes.Remove(pt);
                    context.SaveChanges();
                    rgProdType.Rebind();
                }
                else
                {
                    rnLabel.Text = "ERROR! Can't delete product type. Products in database rely on this entry.";
                    RadNotification.Show();
                }

                //try
                //{
                //    context.ProductTypes.Remove(pt);
                //    context.SaveChanges();
                //}
                //catch (Exception)
                //{
                //    rnLabel.Text = "ERROR! Can't delete product type. Products in database rely on this entry.";
                //    RadNotification.Show();
                //}
            }
        }