protected void Add_Click(object sender, EventArgs e)
 {
     Validation(sender, e);
     if (errormsgs.Count > 0)
     {
         LoadMessageDisplay(errormsgs, "alert alert-info");
     }
     else
     {
         try
         {
             Controller02 sysmgr = new Controller02();
             Entity02     item   = new Entity02();
             item.FirstName  = FirstName.Text.Trim();
             item.LastName   = LastName.Text.Trim();
             item.TeamID     = int.Parse(SupplierList.SelectedValue);
             item.GuardianID = int.Parse(CategoryList.SelectedValue);
             item.Age        = int.Parse(Age.Text);
             item.Gender     = Gender.Text.ToUpper();
             item.AlbertaHealthCareNumber = AlbertaHealthCareNumber.Text.Trim();
             item.MedicalAlertDetails     = MedicalAlertDetails.Text.Trim();
             int newID = sysmgr.Add(item);
             ID.Text = newID.ToString();
             errormsgs.Add("Player has been added");
             LoadMessageDisplay(errormsgs, "alert alert-success");
             UpdateButton.Enabled = true;
             DeleteButton.Enabled = true;
         }
         catch (Exception ex)
         {
             errormsgs.Add(GetInnerException(ex).ToString());
             LoadMessageDisplay(errormsgs, "alert alert-danger");
         }
     }
 }
 protected void Add_Click(object sender, EventArgs e)
 {
     Validation(sender, e);
     if (errormsgs.Count > 0)
     {
         LoadMessageDisplay(errormsgs, "alert alert-info");
     }
     else
     {
         try
         {
             Controller02 sysmgr = new Controller02();
             Entity02     player = new Entity02();
             player.FirstName  = FirstName.Text;
             player.LastName   = LastName.Text;
             player.GuardianID = int.Parse(GuardianList.SelectedValue);
             player.TeamID     = int.Parse(TeamList.SelectedValue);
             player.Age        = int.Parse(Age.Text);
             player.Gender     = Gender.Text.ToUpper();
             player.AlbertaHealthCareNumber = AlbertaHealthCareNumber.Text;
             if (string.IsNullOrEmpty(MedicalAlertDetails.Text))
             {
                 player.MedicalAlertDetails = null;
             }
             else
             {
                 player.MedicalAlertDetails = MedicalAlertDetails.Text;
             }
             //item.Discontinued = false;
             int newID = sysmgr.Add(player);
             ID.Text = newID.ToString();
             errormsgs.Add("Player has been added");
             LoadMessageDisplay(errormsgs, "alert alert-success");
         }
         catch (Exception ex)
         {
             errormsgs.Add(GetInnerException(ex).ToString());
             LoadMessageDisplay(errormsgs, "alert alert-danger");
         }
     }
 }
Пример #3
0
 protected void Add_Click(object sender, EventArgs e)
 {
     Validation(sender, e);
     if (errormsgs.Count > 1)
     {
         LoadMessageDisplay(errormsgs, "alert alert-info");
     }
     else
     {
         try
         {
             Controller02 sysmgr = new Controller02();
             Entity02     item   = new Entity02();
             //No ProductID here as the database will give a new one back when we add
             item.ProductName = Name.Text.Trim(); //NOT NULL
             if (SupplierList.SelectedIndex == 0) //NULL
             {
                 item.SupplierID = null;
             }
             else
             {
                 item.SupplierID = int.Parse(SupplierList.SelectedValue);
             }
             //CategoryID can be NULL in database but NOT NULL when record is added in this CRUD page
             item.CategoryID      = int.Parse(CategoryList.SelectedValue);
             item.QuantityPerUnit =
                 string.IsNullOrEmpty(QuantityPerUnit.Text) ? null : QuantityPerUnit.Text; //NULL
             //UnitPrice can be NULL in database but NOT NULL when record is added in this CRUD page
             item.UnitPrice = decimal.Parse(UnitPrice.Text);
             if (string.IsNullOrEmpty(UnitsInStock.Text)) //NULL
             {
                 item.UnitsInStock = null;
             }
             else
             {
                 item.UnitsInStock = Int16.Parse(UnitsInStock.Text);
             }
             if (string.IsNullOrEmpty(UnitsOnOrder.Text)) //NULL
             {
                 item.UnitsOnOrder = null;
             }
             else
             {
                 item.UnitsOnOrder = Int16.Parse(UnitsOnOrder.Text);
             }
             if (string.IsNullOrEmpty(ReorderLevel.Text)) //NULL
             {
                 item.ReorderLevel = null;
             }
             else
             {
                 item.ReorderLevel = Int16.Parse(ReorderLevel.Text);
             }
             item.Discontinued = false; //NOT NULL
             int newID = sysmgr.Add(item);
             ID.Text = newID.ToString();
             errormsgs.Add("Record has been added");
             LoadMessageDisplay(errormsgs, "alert alert-success");
             UpdateButton.Enabled = true;
             DeleteButton.Enabled = true;
             Discontinued.Enabled = true;
         }
         catch (Exception ex)
         {
             errormsgs.Add(GetInnerException(ex).ToString());
             LoadMessageDisplay(errormsgs, "alert alert-danger");
         }
     }
 }
Пример #4
0
        protected void Add_Click(object sender, EventArgs e)
        {
            bool validdata = Validation(sender, e);

            if (validdata)
            {
                try
                {
                    Controller02 sysmgr = new Controller02();
                    Entity02     item   = new Entity02();
                    item.ProductName = ProductName.Text.Trim();
                    if (CategoryList.SelectedIndex == 0)
                    {
                        item.CategoryID = null;
                    }
                    else
                    {
                        item.CategoryID = int.Parse(CategoryList.SelectedValue);
                    }
                    if (SupplierList.SelectedIndex == 0)
                    {
                        item.SupplierID = null;
                    }
                    else
                    {
                        item.SupplierID = int.Parse(SupplierList.SelectedValue);
                    }
                    item.QuantityPerUnit =
                        string.IsNullOrEmpty(QuantityPerUnit.Text) ? null : QuantityPerUnit.Text;
                    if (string.IsNullOrEmpty(UnitPrice.Text))
                    {
                        item.UnitPrice = null;
                    }
                    else
                    {
                        item.UnitPrice = decimal.Parse(UnitPrice.Text);
                    }
                    if (string.IsNullOrEmpty(UnitsInStock.Text))
                    {
                        item.UnitsInStock = null;
                    }
                    else
                    {
                        item.UnitsInStock = Int16.Parse(UnitsInStock.Text);
                    }
                    if (string.IsNullOrEmpty(UnitsOnOrder.Text))
                    {
                        item.UnitsOnOrder = null;
                    }
                    else
                    {
                        item.UnitsOnOrder = Int16.Parse(UnitsOnOrder.Text);
                    }
                    if (string.IsNullOrEmpty(ReorderLevel.Text))
                    {
                        item.ReorderLevel = null;
                    }
                    else
                    {
                        item.ReorderLevel = Int16.Parse(ReorderLevel.Text);
                    }
                    item.Discontinued = false;
                    int newProductID = sysmgr.Add(item);
                    ProductID.Text = newProductID.ToString();
                    errormsgs.Add("Product has been added");
                    LoadMessageDisplay(errormsgs, "alert alert-success");
                    //BindProductList(); //by default, list will be at index 0
                    //ProductList.SelectedValue = ProductID.Text;
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException.InnerException != null)
                    {
                        errormsgs.Add(updateException.InnerException.Message.ToString());
                    }
                    else
                    {
                        errormsgs.Add(updateException.Message);
                    }
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (var entityValidationErrors in ex.EntityValidationErrors)
                    {
                        foreach (var validationError in entityValidationErrors.ValidationErrors)
                        {
                            errormsgs.Add(validationError.ErrorMessage);
                        }
                    }
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
 protected void Add_Click(object sender, EventArgs e)
 {
     Validation(sender, e);
     if (errormsgs.Count > 0)
     {
         LoadMessageDisplay(errormsgs, "alert alert-info");
     }
     else
     {
         try
         {
             Controller02 sysmgr = new Controller02();
             Entity02     item   = new Entity02();
             item.ProductName = Name.Text.Trim();
             if (SupplierList.SelectedIndex == 0)
             {
                 item.SupplierID = null;
             }
             else
             {
                 item.SupplierID = int.Parse(SupplierList.SelectedValue);
             }
             item.QuantityPerUnit =
                 string.IsNullOrEmpty(QuantityPerUnit.Text) ? null : QuantityPerUnit.Text;
             if (string.IsNullOrEmpty(UnitPrice.Text))
             {
                 item.UnitPrice = null;
             }
             else
             {
                 item.UnitPrice = decimal.Parse(UnitPrice.Text);
             }
             if (string.IsNullOrEmpty(UnitsInStock.Text))
             {
                 item.UnitsInStock = null;
             }
             else
             {
                 item.UnitsInStock = Int16.Parse(UnitsInStock.Text);
             }
             if (string.IsNullOrEmpty(UnitsOnOrder.Text))
             {
                 item.UnitsOnOrder = null;
             }
             else
             {
                 item.UnitsOnOrder = Int16.Parse(UnitsOnOrder.Text);
             }
             if (string.IsNullOrEmpty(ReorderLevel.Text))
             {
                 item.ReorderLevel = null;
             }
             else
             {
                 item.ReorderLevel = Int16.Parse(ReorderLevel.Text);
             }
             item.Discontinued = false;
             int newID = sysmgr.Add(item);
             ID.Text = newID.ToString();
             errormsgs.Add("Product has been added");
             LoadMessageDisplay(errormsgs, "alert alert-success");
         }
         catch (Exception ex)
         {
             errormsgs.Add(GetInnerException(ex).ToString());
             LoadMessageDisplay(errormsgs, "alert alert-danger");
         }
     }
 }