コード例 #1
0
 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");
         }
     }
 }
コード例 #2
0
        protected void Update_Click(object sender, EventArgs e)
        {
            int id = 0;

            if (string.IsNullOrEmpty(ID.Text))
            {
                errormsgs.Add("Search for a Player to update");
            }
            else if (!int.TryParse(ID.Text, out id))
            {
                errormsgs.Add("Id is invalid");
            }
            Validation(sender, e);
            if (errormsgs.Count > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    Controller02 sysmgr = new Controller02();
                    Entity02     item   = new Entity02();
                    item.PlayerID  = int.Parse(ID.Text);
                    item.FirstName = FirstName.Text.Trim();
                    item.LastName  = LastName.Text.Trim();
                    item.Gender    = Gender.Text.ToUpper().Trim();
                    item.Age       = int.Parse(Age.Text);
                    item.AlbertaHealthCareNumber = AlbertaHealthCareNumber.Text.Trim();
                    item.MedicalAlertDetails     = MedicalAlertDetails.Text.Trim();

                    if (SupplierList.SelectedIndex == 0)
                    {
                        item.TeamID = null;
                    }
                    else
                    {
                        item.TeamID = int.Parse(SupplierList.SelectedValue);
                    }
                    item.GuardianID = int.Parse(CategoryList.SelectedValue);

                    int rowsaffected = sysmgr.Update(item);
                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Record has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                    }
                    else
                    {
                        errormsgs.Add("Record was not found");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                    }
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
コード例 #3
0
        protected void Update_Click(object sender, EventArgs e)
        {
            int id = 0;

            if (string.IsNullOrEmpty(ID.Text))
            {
                errormsgs.Add("Search for a player to update");
            }
            else if (!int.TryParse(ID.Text, out id))
            {
                errormsgs.Add("Id is invalid");
            }
            Validation(sender, e);
            if (errormsgs.Count > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    Controller02 sysmgr = new Controller02();
                    Entity02     player = new Entity02();
                    player.PlayerID   = int.Parse(ID.Text);
                    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 = Discontinued.Checked;
                    int rowsaffected = sysmgr.Update(player);
                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Player has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                    }
                    else
                    {
                        errormsgs.Add("Player was not found");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                    }
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
コード例 #4
0
        protected void Update_Click(object sender, EventArgs e)
        {
            int id = 0;

            if (string.IsNullOrEmpty(PlayerID.Text))
            {
                errormsgs.Add("Search for a record to update");
            }
            else if (!int.TryParse(PlayerID.Text, out id))
            {
                errormsgs.Add("ID is invalid");
            }
            Validation(sender, e);
            if (errormsgs.Count > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-danger");
            }
            else
            {
                try
                {
                    Controller02 sysmgr = new Controller02();
                    Entity02     item   = new Entity02();
                    item.PlayerID   = int.Parse(PlayerID.Text);
                    item.TeamID     = int.Parse(TeamList.SelectedValue);
                    item.GuardianID = int.Parse(GuardianList.SelectedValue);
                    item.FirstName  = FirstName.Text.Trim();
                    item.LastName   = LastName.Text.Trim();
                    item.Age        = int.Parse(Age.Text);
                    //item.Gender = Gender.Text;
                    if (RadioMale.Checked)
                    {
                        item.Gender = "M";
                    }
                    else if (RadioFemale.Checked)
                    {
                        item.Gender = "F";
                    }
                    item.AlbertaHealthCareNumber = AlbertaHealthcareNumber.Text;
                    item.MedicalAlertDetails     = string.IsNullOrEmpty(MedicalAlertDetails.Text) ? null : MedicalAlertDetails.Text;
                    int rowsaffected = sysmgr.Player_Update(item);
                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Record has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                    }
                    else
                    {
                        errormsgs.Add("Record was not found");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                    }
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
コード例 #5
0
 public int Update(Entity02 item)
 {
     using (var context = new Context())
     {
         context.Entry(item).State = System.Data.Entity.EntityState.Modified;
         return(context.SaveChanges());
     }
 }
コード例 #6
0
 public int Add(Entity02 item)
 {
     using (var context = new Context())
     {
         context.Entity02s.Add(item);
         context.SaveChanges();
         return(item.ProductID);
     }
 }
コード例 #7
0
        public static void DemoMultipleRepos( int id )
        {
            //Demo: gebruik van meerdere Repo's binnen één transactie;

            using (var repo01 = new RepoEntity01( UOW.Create( ) ))
            {
                var list01 = repo01.GetActive( ).ToList( );

                var repo02 = new RepoEntity02( repo01.UnitOfWork );

                var entity01 = new Entity02( );
                repo02.Update( entity01 );
            }
        }
コード例 #8
0
 //private static List<Entity02> Entity02List = new List<Entity02>();
 protected void Page_Load(object sender, EventArgs e)
 {
     Message.DataSource = null;
     Message.DataBind();
     if (!Page.IsPostBack)
     {
         pagenum = Request.QueryString["page"];
         pid     = Request.QueryString["pid"];
         add     = Request.QueryString["add"];
         BindGuardianList();
         BindTeamList();
         if (string.IsNullOrEmpty(pid))
         {
             Response.Redirect("~/Default.aspx");
         }
         //else if (add == "yes")
         //{
         //    //Discontinued.Enabled = false;
         //}
         else if (add == "no")
         {
             Controller02 sysmgr = new Controller02();
             Entity02     info   = null;
             info = sysmgr.FindByPKID(int.Parse(pid));
             if (info == null)
             {
                 errormsgs.Add("Record is no longer on file.");
                 LoadMessageDisplay(errormsgs, "alert alert-info");
                 Clear_Click(sender, e);
             }
             else
             {
                 ID.Text                      = info.PlayerID.ToString();
                 FirstName.Text               = info.FirstName;
                 LastName.Text                = info.LastName;
                 GuardianList.SelectedValue   = info.GuardianID.ToString();
                 TeamList.SelectedValue       = info.TeamID.ToString();
                 Age.Text                     = info.Age.ToString();
                 Gender.Text                  = info.Gender.ToUpper();
                 AlbertaHealthCareNumber.Text = info.AlbertaHealthCareNumber;
                 MedicalAlertDetails.Text     =
                     info.MedicalAlertDetails == null ? "" : info.MedicalAlertDetails;
             }
         }
     }
 }
コード例 #9
0
        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(TeamList.SelectedValue);
                    item.GuardianID = int.Parse(GuardianList.SelectedValue);

                    item.Age = int.Parse(Age.Text);
                    //item.Gender = string.IsNullOrEmpty(Gender.Text) ? null : Gender.Text;
                    if (RadioMale.Checked)
                    {
                        item.Gender = "M";
                    }
                    else if (RadioFemale.Checked)
                    {
                        item.Gender = "F";
                    }
                    item.AlbertaHealthCareNumber = AlbertaHealthcareNumber.Text;
                    item.MedicalAlertDetails     = string.IsNullOrEmpty(MedicalAlertDetails.Text) ? null : MedicalAlertDetails.Text;
                    int newID = sysmgr.Player_Add(item);
                    PlayerID.Text = newID.ToString();
                    errormsgs.Add("Record 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");
                }
            }
        }
コード例 #10
0
 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");
         }
     }
 }
コード例 #11
0
        public void ExcelEntity_CheckOuterXml_03()
        {
            // Arrange
            var expectedXml = @"<xx:entity><xx:tag id=""id"" name=""name"" /></xx:entity>";

            var entity01 = new Entity01();

            entity01.Attributes.Add("id", "id");
            entity01.Attributes.Add("name", "name");

            var entity02 = new Entity02();

            entity02.Items = new List <ExcelEntity>()
            {
                entity01
            };

            // Act
            var outerXml = entity02.OuterXml;

            // Assert
            Assert.AreEqual(expectedXml, outerXml);
        }
コード例 #12
0
        protected void Update_Click(object sender, EventArgs e)
        {
            int id = 0;

            if (string.IsNullOrEmpty(ID.Text))
            {
                errormsgs.Add("Search for a record to update");
            }
            else if (!int.TryParse(ID.Text, out id))
            {
                errormsgs.Add("Id is invalid");
            }
            Validation(sender, e);
            if (errormsgs.Count > 1)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    Controller02 sysmgr = new Controller02();
                    Entity02     item   = new Entity02();
                    item.ProductID   = int.Parse(ID.Text);
                    item.ProductName = Name.Text.Trim();
                    if (SupplierList.SelectedIndex == 0)
                    {
                        item.SupplierID = null;
                    }
                    else
                    {
                        item.SupplierID = int.Parse(SupplierList.SelectedValue);
                    }
                    item.CategoryID      = int.Parse(CategoryList.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 = Discontinued.Checked;
                    int rowsaffected = sysmgr.Update(item);
                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Record has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                    }
                    else
                    {
                        errormsgs.Add("Record was not found");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                    }
                }
                catch (Exception ex)
                {
                    errormsgs.Add(GetInnerException(ex).ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-danger");
                }
            }
        }
コード例 #13
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");
         }
     }
 }
コード例 #14
0
 protected void Page_Load(object sender, EventArgs e)
 {
     errormsgs.Clear();
     Message.DataSource = null;
     Message.DataBind();
     if (!Page.IsPostBack)
     {
         errormsgs.Add("IsPostBack = False");
         LoadMessageDisplay(errormsgs, "alert alert-info");
         pagenum = Request.QueryString["page"];
         pid     = Request.QueryString["pid"];
         add     = Request.QueryString["add"];
         BindCategoryList();
         BindSupplierList();
         if (string.IsNullOrEmpty(pid))
         {
             Response.Redirect("~/Default.aspx");
         }
         else if (add == "yes")
         {
             Discontinued.Enabled = false;
             UpdateButton.Enabled = false;
             DeleteButton.Enabled = false;
         }
         else
         {
             AddButton.Enabled = false;
             Controller02 sysmgr = new Controller02();
             Entity02     info   = null;
             info = sysmgr.FindByPKID(int.Parse(pid));
             if (info == null)
             {
                 errormsgs.Add("Record is not in Database.");
                 LoadMessageDisplay(errormsgs, "alert alert-info");
                 Clear(sender, e);
             }
             else
             {
                 ID.Text   = info.ProductID.ToString(); //NOT NULL
                 Name.Text = info.ProductName;          //NOT NULL
                 if (info.CategoryID.HasValue)          //NULL
                 {
                     CategoryList.SelectedValue = info.CategoryID.ToString();
                 }
                 else
                 {
                     CategoryList.SelectedIndex = 0;
                 }
                 if (info.SupplierID.HasValue) //NULL
                 {
                     SupplierList.SelectedValue = info.SupplierID.ToString();
                 }
                 else
                 {
                     SupplierList.SelectedIndex = 0;
                 }
                 QuantityPerUnit.Text =
                     info.QuantityPerUnit == null ? "" : info.QuantityPerUnit;                       //NULL
                 UnitPrice.Text =
                     info.UnitPrice.HasValue ? string.Format("{0:0.00}", info.UnitPrice.Value) : ""; //NULL
                 UnitsInStock.Text =
                     info.UnitsInStock.HasValue ? info.UnitsInStock.Value.ToString() : "";           //NULL
                 UnitsOnOrder.Text =
                     info.UnitsOnOrder.HasValue ? info.UnitsOnOrder.Value.ToString() : "";           //NULL
                 ReorderLevel.Text =
                     info.ReorderLevel.HasValue ? info.ReorderLevel.Value.ToString() : "";           //NULL
                 Discontinued.Checked = info.Discontinued;                                           //NOT NULL
             }
         }
     }
     else
     {
         errormsgs.Add("IsPostBack = True");
     }
 }
コード例 #15
0
 protected void Page_Load(object sender, EventArgs e)
 {
     Message.DataSource = null;
     Message.DataBind();
     if (!Page.IsPostBack)
     {
         pagenum = Request.QueryString["page"];
         pid     = Request.QueryString["pid"];
         add     = Request.QueryString["add"];
         errormsgs.Add("The page you came from is: " + pagenum);
         errormsgs.Add("You passed this ProductID: " + pid);
         errormsgs.Add("You passed this Add option: " + add);
         LoadMessageDisplay(errormsgs, "alert alert-info");
         BindCategoryList();
         BindSupplierList();
         if (string.IsNullOrEmpty(pid))
         {
             Response.Redirect("~/Default.aspx");
         }
         else if (add == "yes")
         {
             Discontinued.Enabled = false;
         }
         else
         {
             Controller02 sysmgr = new Controller02();
             Entity02     info   = null;
             info = sysmgr.FindByPKID(int.Parse(pid));
             if (info == null)
             {
                 errormsgs.Add("Product is no longer on file.");
                 LoadMessageDisplay(errormsgs, "alert alert-info");
                 Clear_Click(sender, e);
             }
             else
             {
                 ProductID.Text       = info.ProductID.ToString();
                 ProductName.Text     = info.ProductName;
                 QuantityPerUnit.Text =
                     info.QuantityPerUnit == null ? "" : info.QuantityPerUnit;
                 UnitPrice.Text =
                     info.UnitPrice.HasValue ? string.Format("{0:0.00}", info.UnitPrice.Value) : "";
                 UnitsInStock.Text =
                     info.UnitsInStock.HasValue ? info.UnitsInStock.Value.ToString() : "";
                 UnitsOnOrder.Text =
                     info.UnitsOnOrder.HasValue ? info.UnitsOnOrder.Value.ToString() : "";
                 ReorderLevel.Text =
                     info.ReorderLevel.HasValue ? info.ReorderLevel.Value.ToString() : "";
                 Discontinued.Checked = info.Discontinued;
                 if (info.CategoryID.HasValue)
                 {
                     CategoryList.SelectedValue = info.CategoryID.ToString();
                 }
                 else
                 {
                     CategoryList.SelectedIndex = 0;
                 }
                 if (info.SupplierID.HasValue)
                 {
                     SupplierList.SelectedValue = info.SupplierID.ToString();
                 }
                 else
                 {
                     SupplierList.SelectedIndex = 0;
                 }
             }
         }
     }
 }
コード例 #16
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");
                }
            }
        }
コード例 #17
0
 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");
         }
     }
 }
コード例 #18
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Message.DataSource = null;
            Message.DataBind();
            if (!Page.IsPostBack)
            {
                pagenum = Request.QueryString["page"];
                pid     = Request.QueryString["pid"];
                add     = Request.QueryString["add"];
                BindCategoryList();
                BindSupplierList();
                if (string.IsNullOrEmpty(pid))
                {
                    Response.Redirect("~/Default.aspx");
                }
                else if (add == "yes")
                {
                    UpdateButton.Enabled = false;
                    DeleteButton.Enabled = false;
                }
                else
                {
                    AddButton.Enabled = false;
                    Controller02 sysmgr = new Controller02();
                    Entity02     info   = null;
                    info = sysmgr.FindByPLID(int.Parse(pid));
                    if (info == null)
                    {
                        errormsgs.Add("Record is no longer on file.");
                        LoadMessageDisplay(errormsgs, "alert alert-info");
                        Clear_Click(sender, e);
                    }
                    else
                    {
                        ID.Text        = info.PlayerID.ToString();
                        FirstName.Text = info.FirstName;
                        LastName.Text  = info.LastName;
                        Age.Text       = info.Age.ToString();
                        Gender.Text    = info.Gender;
                        AlbertaHealthCareNumber.Text = info.AlbertaHealthCareNumber;
                        MedicalAlertDetails.Text     = info.MedicalAlertDetails;


                        if (info.GuardianID.HasValue)
                        {
                            CategoryList.SelectedValue = info.GuardianID.ToString();
                        }
                        else
                        {
                            CategoryList.SelectedIndex = 0;
                        }
                        if (info.TeamID.HasValue)
                        {
                            SupplierList.SelectedValue = info.TeamID.ToString();
                        }
                        else
                        {
                            SupplierList.SelectedIndex = 0;
                        }
                    }
                }
            }
        }