Exemple #1
0
        public ActionResult Create([Bind(Include = "JOBNO,SDATE,EDATE,STAFFCODE,REM,ROWNO,STAMP")] CSJOBSTF cSJOBSTF)
        {
            if (ModelState.IsValid)
            {
                CSJOBSTF lastRec = db.CSJOBSTFs.Where(x => x.JOBNO == cSJOBSTF.JOBNO).OrderByDescending(z => z.ROWNO).FirstOrDefault();
                int      rowno   = 1;
                if (lastRec != null)
                {
                    rowno                   = lastRec.ROWNO + 1;
                    lastRec.EDATE           = cSJOBSTF.SDATE;
                    lastRec.STAMP           = lastRec.STAMP + 1;
                    db.Entry(lastRec).State = EntityState.Modified;
                }

                cSJOBSTF.STAMP = 0;
                cSJOBSTF.ROWNO = rowno;

                CSJOBM cSJOBM = db.CSJOBMs.Find(cSJOBSTF.JOBNO);
                cSJOBM.JOBSTAFF = cSJOBSTF.STAFFCODE;
                cSJOBM.STAMP    = cSJOBM.STAMP + 1;
                try
                {
                    db.Entry(cSJOBM).State = EntityState.Modified;
                    db.CSJOBSTFs.Add(cSJOBSTF);
                    db.SaveChanges();

                    int page = (int)Session["CSJOBDPage"];
                    return(RedirectToAction("Index", "CSJOBDs", new { page = page }));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }

            ViewBag.STAFFCODE = new SelectList(db.HKSTAFFs, "STAFFCODE", "STAFFDESC", cSJOBSTF.STAFFCODE);
            return(View(cSJOBSTF));
        }
        protected void RemoveProduct_Click(object sender, EventArgs e)
        {
            //on an update, you MUST ENSURE that the primary key value
            //   exists for use by the update
            int productid = 0;
            if (!int.TryParse(ProductID.Text.Trim(), out productid))
            {
                errormsgs.Add("Invalid or missing Product ID");
            }


            //all code behind logical validation errors are
            //    captured and reported at once
            if (errormsgs.Count() > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    //connect to the appropriate BLL controller
                    ProductController sysmgr = new ProductController();
                    //issue a call to the appropriate BLL controller method
                    int rowsaffected = sysmgr.Product_Delete(int.Parse(ProductID.Text.Trim()));
                    //Handle results
                    if (rowsaffected == 0)
                    {
                        errormsgs.Add(ProductName.Text + " has been not been discontinued. Search for product again.");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                        BindProductList();
                    }
                    else
                    {
                        errormsgs.Add(ProductName.Text + " has been discontinued");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        BindProductList();
                        //ONLY if it is a LOGOICAL DELETE
                        ProductList.SelectedValue = ProductID.Text;
                        Discontinued.Checked = true;
                    }

                }
                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");
                }
            }
        }
Exemple #3
0
        protected void AddProduct_Click(object sender, EventArgs e)
        {
            //ensure validation is still good
            if (Page.IsValid)
            {
                //event code validation that was not accomplished on
                //   the web form
                //examples
                //Assume that the CategoryID is required
                if (CategoryList.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (QuantityPerUnit.Text.Length > 20)
                {
                    errormsgs.Add("Quantity per Unit is limited to 20 characters");
                }

                //check if click event validation is good
                if (errormsgs.Count > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    //assume taht the data is validate to our knowledge
                    try
                    {
                        //standard add to a database
                        //connect to the appropriate controller
                        ProductController sysmgr = new ProductController();
                        //create and load an instance of the entity record
                        //  since there was no constructor placed in the
                        //  entity, when one creaes the instance the
                        //  default system construtor will be used
                        Product item = new Product();
                        //what about ProductID??
                        //   since ProductID is an identity field it does NOT
                        //   need to be loaded into the new instance
                        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);
                        }
                        //what about Discontinued??
                        item.Discontinued = false;
                        //issue the BLL call
                        int newProductID = sysmgr.Products_Add(item);
                        //give feedback
                        //if you get to execute the feedback code, it means
                        //    that the product has been successfully added to
                        //    the database
                        ProductID.Text = newProductID.ToString();
                        errormsgs.Add("Product has been added");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        //is there any other controls on the form that need to be refreshed
                        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");
                    }
                }
            }
        }
Exemple #4
0
        protected void RemoveProduct_Click(object sender, EventArgs e)
        {
            //on the update you MUST ensure that the record's pkey value is present
            if (string.IsNullOrEmpty(ProductID.Text.Trim()))
            {
                errormsgs.Add("Search for the product to be maintained.");
            }

            //did one pass all logic validation
            if (errormsgs.Count() > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    //connect to appropriate BLL class
                    ProductController sysgmr = new ProductController();
                    //issue a call to the appropriate BLL method passing
                    //   the instance of <T>
                    int rowsaffected = sysgmr.Product_Delete(int.Parse(ProductID.Text.Trim()));
                    //handle the results
                    if (rowsaffected == 0)
                    {
                        errormsgs.Add(ProductName.Text + " has not been discontinued. Search the product again");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                        //consider refreshing the necessary controls on your form
                        BindProductList();
                        ProductID.Text = "";
                    }
                    else
                    {
                        errormsgs.Add(ProductName.Text + " has been discontinued");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        //consider refreshing the necessary controls on your form

                        ////physical delete
                        //BindProductList();
                        //ProductID.Text = "";
                        ////optionally, clear the form, client decision
                        //Clear_Click(sender, new EventArgs());


                        //logical delete
                        BindProductList();
                        //refresh form controls to indicate removal
                        Discontinued.Checked      = true;
                        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 AddProduct_Click(object sender, EventArgs e)
        {
            //if (Page.IsValid)
            //{
                //add any addition logic validation required for
                //    processing
                //in this example we will assume the supplier id
                //    and category id are required
                if (SupplierList.SelectedIndex == 0)
                {
                    errormsgs.Add("Please select a supplier");
                }
                if (CategoryList.SelectedIndex == 0)
                {
                    errormsgs.Add("Please select a category");
                }
                //all code behind logical validation errors are
                //    captured and reported at once
                if(errormsgs.Count() > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    try
                    {
                    //create an instance of Product
                    Product item = new Product();
                    //collect the data from the web form and place
                    //   in the Product instance
                    item.ProductName = ProductName.Text;
                        item.SupplierID = int.Parse(SupplierList.SelectedValue);
                    item.CategoryID = int.Parse(CategoryList.SelectedValue);
                    item.QuantityPerUnit = string.IsNullOrEmpty(QuantityPerUnit.Text.Trim()) ? null : QuantityPerUnit.Text.Trim();
                    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);
                    }
                    //handling of the Discontinued can be done manually
                    //    or logically
                    item.Discontinued = false;

                    //connect to the appropriate BLL controller
                    ProductController sysmgr = new ProductController();
                    //issue a call to the appropriate BLL controller method
                    int newProductID = sysmgr.Product_Add(item);
                    //Handle results
                    errormsgs.Add(ProductName.Text + " has been added to the database with a key of " + newProductID.ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-success");

                    //also if any control on this form uses this new instance
                    //    for a query or other action, you must update (refresh)
                    //    that control
                    BindProductList();
                    ProductID.Text = newProductID.ToString();
                    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");
                    }

                }
            //}
        }
Exemple #6
0
        public ActionResult Create([Bind(Include = "CONO,EFFDATE,EQCODE,EQCONSIDER,NOOFSHARES,NOMINAL,PAIDAMT,DUEAMT,PREMIUM,NCDETStr,NCDET,ENDDATE,ROWNO,STAMP")] CSCOPUK cSCOPUK)
        {
            if (ModelState.IsValid)
            {
                int lastRowNo = 0;
                try
                {
                    lastRowNo = db.CSCOPUKs.Where(m => m.CONO == cSCOPUK.CONO).Max(n => n.ROWNO);
                }
                catch (Exception e) { lastRowNo = 0; }
                finally { };

                try
                {
                    cSCOPUK.ROWNO = lastRowNo + 1;
                    cSCOPUK.STAMP = 0;
                    db.CSCOPUKs.Add(cSCOPUK);
                    db.SaveChanges();
                    return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOPUK.CONO) }) + "#PaidUp"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }

            ViewBag.EQCODE     = new SelectList(db.CSEQs, "EQCODE", "EQDESC", cSCOPUK.EQCODE);
            ViewBag.EQCONSIDER = cSCOPUK.consideration;
            cSCOPUK.CSCOMSTR   = db.CSCOMSTRs.Find(cSCOPUK.CONO);
            return(View(cSCOPUK));
        }
Exemple #7
0
        protected void AddProduct_Click(object sender, EventArgs e)
        {
            //execute your form validation
            //if (Page.IsValid)
            //{
            //any logic validation on covered by form validation
            //for this example, I will assume that the CategoryID
            //     and SupplierID are needed
            if (SupplierList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a supplier");
            }
            if (CategoryList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a category");
            }

            //did one pass all logic validation
            if (errormsgs.Count() > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    //create an instance of <T>
                    Product item = new Product();
                    //extract data from form and load <T>
                    item.ProductName     = ProductName.Text;
                    item.SupplierID      = int.Parse(SupplierList.SelectedValue);
                    item.CategoryID      = int.Parse(CategoryList.SelectedValue);
                    item.QuantityPerUnit = string.IsNullOrEmpty(QuantityPerUnit.Text.Trim()) ?
                                           null : QuantityPerUnit.Text;
                    if (string.IsNullOrEmpty(UnitPrice.Text.Trim()))
                    {
                        item.UnitPrice = null;
                    }
                    else
                    {
                        item.UnitPrice = decimal.Parse(UnitPrice.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(UnitsInStock.Text.Trim()))
                    {
                        item.UnitsInStock = null;
                    }
                    else
                    {
                        item.UnitsInStock = Int16.Parse(UnitsInStock.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(UnitsOnOrder.Text.Trim()))
                    {
                        item.UnitsOnOrder = null;
                    }
                    else
                    {
                        item.UnitsOnOrder = Int16.Parse(UnitsOnOrder.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(ReorderLevel.Text.Trim()))
                    {
                        item.ReorderLevel = null;
                    }
                    else
                    {
                        item.ReorderLevel = Int16.Parse(ReorderLevel.Text.Trim());
                    }
                    //logically this is a new product, therefore discontinued can
                    //    be set for the user to false
                    item.Discontinued = false;
                    //connect to appropriate BLL class
                    ProductController sysgmr = new ProductController();
                    //issue a call to the appropriate BLL method passing
                    //   the instance of <T>
                    int newProductID = sysgmr.Product_Add(item);
                    //handle the results
                    errormsgs.Add(ProductName.Text + " has been added to the database with an id of " + newProductID.ToString());
                    LoadMessageDisplay(errormsgs, "alert alert-success");

                    //refresh of the web page/web controls
                    //display the new productid in its field
                    ProductID.Text = newProductID.ToString();
                    BindProductList();
                    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 Update_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (GuardianID.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (TeamID.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (PlayerGender.SelectedIndex != 0 && PlayerGender.SelectedIndex != 1)
                {
                    errormsgs.Add("A Player Gender is required.");
                }
                int playerid = 0;
                if (string.IsNullOrEmpty(PlayerID.Text))
                {
                    errormsgs.Add("Search for a player to update");
                }
                else if (!int.TryParse(PlayerID.Text, out playerid))
                {
                    errormsgs.Add("Player id is invalid");
                }
                else if (playerid < 1)
                {
                    errormsgs.Add("Player id is invalid");
                }

                //is data still good
                if (errormsgs.Count > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    try
                    {
                        PlayerController sysmgr = new PlayerController();
                        Player           item   = new Player();
                        item.PlayerID   = playerid;
                        item.GuardianID = int.Parse(GuardianID.SelectedValue);

                        item.TeamId = int.Parse(TeamID.SelectedValue);

                        item.FirstName = FirstName.Text.Trim();

                        item.LastName = LastName.Text.Trim();

                        item.Age = int.Parse(PlayerAge.Text);

                        item.Gender = PlayerAge.Text.Trim();

                        item.AlbertaHealthCareNumber = AlbertaHealthCareNumber.Text.Trim();

                        item.MedicalAlertDetails =
                            string.IsNullOrEmpty(MedicalAlerts.Text) ? null : MedicalAlerts.Text.Trim();

                        //issue the BLL call
                        int rowsaffected = sysmgr.Products_Update(item);

                        //give feedback
                        if (rowsaffected > 0)
                        {
                            errormsgs.Add("Product has been updated");
                            LoadMessageDisplay(errormsgs, "alert alert-success");
                            //is there any other controls on the form that
                            //   need to be refreshed??
                            BindPlayerList(); //by default, list will be at index 0
                            PlayerSearch.SelectedValue = PlayerID.Text;
                        }
                        else
                        {
                            errormsgs.Add("Product has not been updated. Product was not found");
                            LoadMessageDisplay(errormsgs, "alert alert-warning");
                            BindPlayerList();

                            //optionally you could clear your fields
                        }
                    }
                    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 Delete_Click(object sender, EventArgs e)
        {
            int playerid = 0;

            if (string.IsNullOrEmpty(PlayerID.Text))
            {
                errormsgs.Add("Search for a product to update");
            }
            else if (!int.TryParse(PlayerID.Text, out playerid))
            {
                errormsgs.Add("Product id is invalid");
            }
            else if (playerid < 1)
            {
                errormsgs.Add("Product id is invalid");
            }

            //is data still good
            if (errormsgs.Count > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    PlayerController sysmgr = new PlayerController();
                    int rowsaffected        = sysmgr.Players_Delete(playerid);

                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Player has been removed");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                    }
                    else
                    {
                        errormsgs.Add("Player already removed");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                    }
                }
                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");
                }
            }
        }
Exemple #10
0
        public ActionResult Edit([Bind(Include = "PRSCODE,CTRYCODE,REGTYPE,REGNO,REM,STAMP")] CSPRSREG cSPRSREG)
        {
            if (ModelState.IsValid)
            {
                cSPRSREG.STAMP = cSPRSREG.STAMP + 1;
                try
                {
                    bool     changed = false;
                    CSPRSREG csOrig  = (CSPRSREG)Session["CSPRSREG_ORIG"];
                    if (csOrig.CTRYCODE != cSPRSREG.CTRYCODE)
                    {
                        changed = true;
                    }
                    if (csOrig.REGTYPE != cSPRSREG.REGTYPE)
                    {
                        changed = true;
                    }
                    if (csOrig.REGNO != cSPRSREG.REGNO)
                    {
                        changed = true;
                    }

                    if (changed)
                    {
                        CSPRSREG csDel = db.CSPRSREGs.Find(csOrig.PRSCODE, csOrig.CTRYCODE, csOrig.REGTYPE, csOrig.REGNO);;
                        db.CSPRSREGs.Remove(csDel);
                        db.CSPRSREGs.Add(cSPRSREG);
                    }
                    else
                    {
                        db.Entry(cSPRSREG).State = EntityState.Modified;
                    }


                    db.SaveChanges();
                    return(RedirectToAction("Edit", "CSPRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSPRSREG.PRSCODE) }));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }
            ViewBag.PRSCODE  = MyHtmlHelpers.ConvertByteStrToId(cSPRSREG.PRSCODE);
            ViewBag.REGTYPE  = new SelectList(db.HKREGTYPEs.Select(x => new { REGTYPE = x.REGTYPE, REGDESC = x.CTRYOPR + " | " + x.REGTYPE }), "REGTYPE", "REGDESC");
            ViewBag.CTRYCODE = new SelectList(db.HKCTRies.OrderBy(x => x.CTRYCODE), "CTRYCODE", "CTRYDESC", cSPRSREG.CTRYCODE);
            return(View(cSPRSREG));
        }
        protected void Add_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (GuardianID.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (TeamID.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (PlayerGender.SelectedIndex != 0 && PlayerGender.SelectedIndex != 1)
                {
                    errormsgs.Add("A Player Gender is required.");
                }

                //is data still good
                if (errormsgs.Count > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    try
                    {
                        PlayerController sysmgr = new PlayerController();
                        Player           item   = new Player();

                        item.GuardianID = int.Parse(GuardianID.SelectedValue);

                        item.TeamId = int.Parse(TeamID.SelectedValue);

                        item.FirstName = FirstName.Text.Trim();

                        item.LastName = LastName.Text.Trim();

                        item.Age = int.Parse(PlayerAge.Text);

                        item.Gender = PlayerAge.Text.Trim();

                        item.AlbertaHealthCareNumber = AlbertaHealthCareNumber.Text.Trim();

                        item.MedicalAlertDetails =
                            string.IsNullOrEmpty(MedicalAlerts.Text) ? null : MedicalAlerts.Text.Trim();

                        int newPlayerID = sysmgr.Player_Add(item);


                        PlayerID.Text = newPlayerID.ToString();
                        errormsgs.Add("Player has been added");
                        LoadMessageDisplay(errormsgs, "alert alert-success");

                        BindPlayerList();
                        PlayerSearch.SelectedValue = PlayerID.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 RemoveProduct_Click(object sender, EventArgs e)
        {
            //event code validation that was not accomplished on
            //   the web form
            //examples
            //Assume that the CategoryID is required


            //on delete, ensure you have your primary key value
            int productid = 0;

            if (string.IsNullOrEmpty(ProductID.Text))
            {
                errormsgs.Add("Search for a product to update");
            }
            else if (!int.TryParse(ProductID.Text, out productid))
            {
                errormsgs.Add("Product id is invalid");
            }
            else if (productid < 1)
            {
                errormsgs.Add("Product id is invalid");
            }

            //check if click event validation is good
            if (errormsgs.Count > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                //assume taht the data is validate to our knowledge
                try
                {
                    //standard delete to a database
                    //connect to the appropriate controller
                    ProductController sysmgr = new ProductController();

                    //issue the BLL call
                    int rowsaffected = sysmgr.Products_Delete(productid);
                    //give feedback
                    if (rowsaffected > 0)
                    {
                        errormsgs.Add("Product has been discontinued");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        //is there any other controls on the form that need to be refreshed
                        BindProductList();                          //by default, list will be at index 0
                        ProductList.SelectedValue = ProductID.Text; //logical delete
                        Discontinued.Checked      = true;           //logical delete
                    }
                    else
                    {
                        errormsgs.Add("Product has not been discontinued. Product was not found");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                        //is there any other controls on the form that need to be refreshed
                        BindProductList();     //by default, list will be at index 0

                        //optionally you could clear your fields
                    }
                }
                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");
                }
            }
        }
Exemple #13
0
        public ActionResult Edit([Bind(Include = "CASECODE,CASEDESC,MAPSFIX,STAMP")] CSCASE cSCASE)
        {
            if (ModelState.IsValid)
            {
                ASIDBConnection newdb = new ASIDBConnection();
                try
                {
                    CSCASE curRec = newdb.CSCASEs.Find(cSCASE.CASECODE);
                    if (curRec.STAMP == cSCASE.STAMP)
                    {
                        cSCASE.STAMP           = cSCASE.STAMP + 1;
                        db.Entry(cSCASE).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Record is modified");
                    }
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
                finally
                {
                    newdb.Dispose();
                }
            }
            return(View(cSCASE));
        }
Exemple #14
0
 protected void OnUpdateException(
     ExceptionEventArgs args)
 {
     UpdateException?.Invoke(args);
 }
Exemple #15
0
        public ActionResult Edit([Bind(Include = "CONO,PRSCODE,ADATE,RDATE,ENDDATE,REM,ROWNO,STAMP")] CSCODR cSCODR)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    bool   changed = false;
                    CSCODR csOrig  = (CSCODR)Session["CSCODR_ORIG"];
                    if (csOrig.PRSCODE != cSCODR.PRSCODE)
                    {
                        changed = true;
                    }
                    if (csOrig.ADATE != cSCODR.ADATE)
                    {
                        changed = true;
                    }


                    if (changed)
                    {
                        CSCODR csDel = db.CSCODRs.Find(csOrig.CONO, csOrig.PRSCODE, csOrig.ADATE);
                        db.CSCODRs.Remove(csDel);
                        db.CSCODRs.Add(cSCODR);
                    }
                    else
                    {
                        db.Entry(cSCODR).State = EntityState.Modified;
                    }

                    cSCODR.STAMP = cSCODR.STAMP + 1;

                    db.SaveChanges();
                    return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCODR.CONO) }) + "#Director"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }
            cSCODR.CSCOMSTR   = db.CSCOMSTRs.Find(cSCODR.CONO);
            cSCODR.CSCODRCHGs = db.CSCODRCHGs.Where(x => x.CONO == cSCODR.CONO && x.PRSCODE == cSCODR.PRSCODE && x.ADATE == cSCODR.ADATE).ToList();
            ViewBag.PRSCODE   = new SelectList(db.CSPRS.Where(x => x.HKCONST.CONSTTYPE == "Individual").OrderBy(x => x.PRSNAME), "PRSCODE", "PRSNAME", cSCODR.PRSCODE);
            return(View(cSCODR));
        }
Exemple #16
0
        public ActionResult Create([Bind(Include = "CONO,PRSCODE,ADATE,CHGEFFDATE,CHGREM,PRSNAME,NATION,RACE,ADDRID,OCCUPATION,REGCTRY1,REGTYPE1,REGID1,REGCTRY2,REGTYPE2,REGID2,REM,ROWNO,STAMP")] CSCOAGTCHG cSCOAGTCHG)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    int lastRowNo = 0;
                    try
                    {
                        lastRowNo = db.CSCOAGTCHGs.Where(m => m.CONO == cSCOAGTCHG.CONO && m.PRSCODE == cSCOAGTCHG.PRSCODE && m.ADATE == cSCOAGTCHG.ADATE).Max(n => n.ROWNO);
                    }
                    catch (Exception e) { lastRowNo = 0; }
                    finally { };


                    cSCOAGTCHG.ROWNO = lastRowNo + 1;

                    cSCOAGTCHG.STAMP = 0;
                    db.CSCOAGTCHGs.Add(cSCOAGTCHG);
                    db.SaveChanges();
                    return(new RedirectResult(Url.Action("Edit", "CSCOAGTs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOAGTCHG.CONO), person = cSCOAGTCHG.PRSCODE, adate = cSCOAGTCHG.ADATE })));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }

            ViewBag.NATION = new SelectList(db.HKNATIONs, "NATION", "NATION", cSCOAGTCHG.NATION);
            ViewBag.RACE   = new SelectList(db.HKRACEs, "RACE", "RACE", cSCOAGTCHG.RACE);
            ViewBag.CHGREM = new SelectList(db.CSCHGREMs.OrderBy(x => x.CHGREM), "CHGREM", "CHGREM", cSCOAGTCHG.CHGREM);
            ViewBag.ADDRID = new SelectList(db.CSPRSADDRs.Where(x => x.PRSCODE == cSCOAGTCHG.PRSCODE).OrderBy(y => y.ADDRID).Select(z => new { ADDRID = z.ADDRID, MAILDET = z.ADDRID + " | " + z.MAILADDR + " | " + z.ADDRTYPE + " | " + z.ADDR1 + z.ADDR2 + z.ADDR3 }), "ADDRID", "MAILDET", cSCOAGTCHG.ADDRID);
            ViewBag.REGID1 = new SelectList(db.CSPRSREGs.Where(x => x.PRSCODE == cSCOAGTCHG.PRSCODE).Select(x => new { REGNO = x.REGNO, PRSNAME = x.CTRYCODE + " | " + x.REGTYPE + " | " + x.REGNO }), "REGNO", "PRSNAME", cSCOAGTCHG.REGID1);
            ViewBag.REGID2 = new SelectList(db.CSPRSREGs.Where(x => x.PRSCODE == cSCOAGTCHG.PRSCODE).Select(x => new { REGNO = x.REGNO, PRSNAME = x.CTRYCODE + " | " + x.REGTYPE + " | " + x.REGNO }), "REGNO", "PRSNAME", cSCOAGTCHG.REGID2);
            return(View(cSCOAGTCHG));
        }
Exemple #17
0
        public ActionResult Create([Bind(Include = "CONO,PRSCODE,ADATE,RDATE,ENDDATE,REM,ROWNO,STAMP")] CSCODR cSCODR)
        {
            if (ModelState.IsValid)
            {
                int lastRowNo = 0;
                try
                {
                    lastRowNo = db.CSCODRs.Where(m => m.CONO == cSCODR.CONO).Max(n => n.ROWNO);
                }
                catch (Exception e) { lastRowNo = 0; }
                finally { };

                cSCODR.STAMP = 0;
                try
                {
                    cSCODR.ROWNO = lastRowNo + 1;
                    db.CSCODRs.Add(cSCODR);
                    db.SaveChanges();
                    return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCODR.CONO) }) + "#Director"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
            }
            cSCODR.CSCOMSTR = db.CSCOMSTRs.Find(cSCODR.CONO);
            ViewBag.PRSCODE = new SelectList(db.CSPRS.Where(x => x.HKCONST.CONSTTYPE == "Individual").OrderBy(x => x.PRSNAME), "PRSCODE", "PRSNAME", cSCODR.PRSCODE);
            return(View(cSCODR));
        }
Exemple #18
0
        public ActionResult Create([Bind(Include = "CONO,SDATE,COSTAT,FILETYPE,FILELOC,SEALLOC,EDATE,ROWNO,STAMP")] CSCOSTAT cSCOSTAT)
        {
            if (ModelState.IsValid)
            {
                int lastRowNo = 0;
                try
                {
                    lastRowNo = db.CSCOSTATs.Where(m => m.CONO == cSCOSTAT.CONO).Max(n => n.ROWNO);
                }
                catch (Exception e) { lastRowNo = 0; }
                finally { };

                try
                {
                    cSCOSTAT.STAMP = 0;
                    cSCOSTAT.EDATE = new DateTime(3000, 1, 1);
                    cSCOSTAT.ROWNO = lastRowNo + 1;

                    db.CSCOSTATs.Add(cSCOSTAT);
                    UpdateCompany(cSCOSTAT);
                    UpdatePreviousRow(cSCOSTAT);

                    db.SaveChanges();
                    //return RedirectToAction("Details","CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) });
                    return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) }) + "#Status"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View(cSCOSTAT));
        }
Exemple #19
0
        protected void InsertTeam_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (errormsgs.Count() > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    try
                    {
                        //create an instance of product
                        Team item = new Team();

                        //collect the data from the web form and place in the product instance
                        item.TeamName       = TeamNameV2.Text;
                        item.Coach          = CoachNameV2.Text;
                        item.AssistantCoach = AssistantCoachV2.Text;

                        if (string.IsNullOrEmpty(WinsV2.Text))
                        {
                            item.Wins = 0;
                        }
                        else
                        {
                            item.Wins = int.Parse(WinsV2.Text);
                        }
                        if (string.IsNullOrEmpty(LossesV2.Text))
                        {
                            item.Losses = 0;
                        }
                        else
                        {
                            item.Losses = int.Parse(LossesV2.Text);
                        }
                        TeamController sysmgr = new TeamController();

                        //Issue a call to the apropriate BLL controller method
                        int newTeamID = sysmgr.Team_Add(item);

                        //handle results
                        errormsgs.Add(TeamNameV2.Text + " has been added to the database with a key of " + newTeamID.ToString());
                        LoadMessageDisplay(errormsgs, "alert alert-success");

                        // also if any controll uses this new instance for a query or other action, you must update (refresh) that control
                        BindTeamList();
                        TeamListV2.SelectedValue = newTeamID.ToString();
                    }
                    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");
                    }
                }
            }
        }
Exemple #20
0
        public ActionResult Create1([Bind(Include = "CONO,SDATE,COSTAT,FILETYPE,FILELOC,SEALLOC,EDATE,ROWNO,STAMP")] CSCOSTAT cSCOSTAT)
        {
            int page = (int)Session["CSCOSTATPage"];

            if (ModelState.IsValid)
            {
                int lastRowNo = 0;
                try
                {
                    lastRowNo = db.CSCOSTATs.Where(m => m.CONO == cSCOSTAT.CONO).Max(n => n.ROWNO);
                }
                catch (Exception e) { lastRowNo = -1; }
                finally { };

                try
                {
                    cSCOSTAT.STAMP = 0;
                    cSCOSTAT.EDATE = new DateTime(3000, 1, 1);
                    cSCOSTAT.ROWNO = lastRowNo + 1;

                    db.CSCOSTATs.Add(cSCOSTAT);
                    UpdateCompany(cSCOSTAT);
                    UpdatePreviousRow(cSCOSTAT);

                    db.SaveChanges();

                    return(RedirectToAction("Index", new { page = page }));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }


            ViewBag.CONO      = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME");
            ViewBag.COSTAT    = new SelectList(db.CSSTATs, "COSTAT", "COSTAT", cSCOSTAT.COSTAT);
            ViewBag.page      = page;
            ViewBag.Title     = "Add Company Change Status";
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View(cSCOSTAT));
        }
Exemple #21
0
        protected void UpdateProduct_Click(object sender, EventArgs e)
        {
            //execute your form validation
            //if (Page.IsValid)
            //{
            //any logic validation on covered by form validation
            //for this example, I will assume that the CategoryID
            //     and SupplierID are needed
            if (SupplierList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a supplier");
            }
            if (CategoryList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a category");
            }

            //on the update you MUST ensure that the record's pkey value is present
            if (string.IsNullOrEmpty(ProductID.Text.Trim()))
            {
                errormsgs.Add("Search for the product to be maintained.");
            }

            //did one pass all logic validation
            if (errormsgs.Count() > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    //create an instance of <T>
                    Product item = new Product();
                    //extract data from form and load <T>

                    //on the update you MUST ensure that the record's pkey value
                    //    is loaded to the instance
                    item.ProductID = int.Parse(ProductID.Text.Trim());

                    item.ProductName     = ProductName.Text;
                    item.SupplierID      = int.Parse(SupplierList.SelectedValue);
                    item.CategoryID      = int.Parse(CategoryList.SelectedValue);
                    item.QuantityPerUnit = string.IsNullOrEmpty(QuantityPerUnit.Text.Trim()) ?
                                           null : QuantityPerUnit.Text;
                    if (string.IsNullOrEmpty(UnitPrice.Text.Trim()))
                    {
                        item.UnitPrice = null;
                    }
                    else
                    {
                        item.UnitPrice = decimal.Parse(UnitPrice.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(UnitsInStock.Text.Trim()))
                    {
                        item.UnitsInStock = null;
                    }
                    else
                    {
                        item.UnitsInStock = Int16.Parse(UnitsInStock.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(UnitsOnOrder.Text.Trim()))
                    {
                        item.UnitsOnOrder = null;
                    }
                    else
                    {
                        item.UnitsOnOrder = Int16.Parse(UnitsOnOrder.Text.Trim());
                    }
                    if (string.IsNullOrEmpty(ReorderLevel.Text.Trim()))
                    {
                        item.ReorderLevel = null;
                    }
                    else
                    {
                        item.ReorderLevel = Int16.Parse(ReorderLevel.Text.Trim());
                    }

                    //on an update, you take the value from the control
                    item.Discontinued = Discontinued.Checked;


                    //connect to appropriate BLL class
                    ProductController sysgmr = new ProductController();
                    //issue a call to the appropriate BLL method passing
                    //   the instance of <T>
                    int rowsaffected = sysgmr.Product_Update(item);
                    //handle the results
                    if (rowsaffected == 0)
                    {
                        errormsgs.Add(ProductName.Text + " has not been updated. Search the product again");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                        //consider refreshing the necessary controls on your form
                        BindProductList();
                        ProductID.Text = "";
                    }
                    else
                    {
                        errormsgs.Add(ProductName.Text + " has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        //consider refreshing the necessary controls on your form
                        BindProductList();
                        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");
                }
            }
            //}
        }
Exemple #22
0
        public ActionResult Edit([Bind(Include = "CONO,SDATE,COSTAT,FILETYPE,FILELOC,SEALLOC,EDATE,ROWNO,STAMP")] CSCOSTAT cSCOSTAT)
        {
            if (ModelState.IsValid)
            {
                ASIDBConnection newdb = new ASIDBConnection();
                try
                {
                    CSCOSTAT curRec = newdb.CSCOSTATs.Find(cSCOSTAT.CONO, cSCOSTAT.ROWNO);
                    if (curRec.STAMP == cSCOSTAT.STAMP)
                    {
                        cSCOSTAT.STAMP = cSCOSTAT.STAMP + 1;

                        // only update the latest record
                        if (db.CSCOSTATs.Where(x => x.CONO == cSCOSTAT.CONO).OrderByDescending(x => x.ROWNO).Select(x => x.ROWNO).FirstOrDefault() == cSCOSTAT.ROWNO)
                        {
                            UpdateCompany(cSCOSTAT);
                        }
                        UpdatePreviousRow(cSCOSTAT);

                        db.Entry(cSCOSTAT).State = EntityState.Modified;
                        db.SaveChanges();
                        // return RedirectToAction("Details", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) });
                        return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) }) + "#Status"));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Record is modified");
                    }
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
                finally
                {
                    newdb.Dispose();
                }
            }
            ViewBag.COSTAT    = new SelectList(db.CSSTATs, "COSTAT", "COSTAT", cSCOSTAT.COSTAT);
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View(cSCOSTAT));
        }
        protected void Search_Click(object sender, EventArgs e)
        {
            if ( ProductList.SelectedIndex == 0)
            {
                errormsgs.Add("Select a product from the list to search");
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    ProductController sysmgr = new ProductController();
                    Product datainfo = sysmgr.Product_Get(int.Parse(ProductList.SelectedValue));
                    if (datainfo == null)
                    {
                        errormsgs.Add(ProductList.SelectedItem.Text + " cannot be found. Make another selection");
                        LoadMessageDisplay(errormsgs, "alert alert-info");
                        Clear_Click(sender, e);
                    }
                    else
                    {
                        ProductID.Text = datainfo.ProductID.ToString();
                        ProductName.Text = datainfo.ProductName;
                        QuantityPerUnit.Text = string.IsNullOrEmpty(datainfo.QuantityPerUnit)? "" : datainfo.QuantityPerUnit;
                        UnitPrice.Text = string.IsNullOrEmpty(datainfo.UnitPrice.ToString()) ? "" : string.Format("{0:0.00}",datainfo.UnitPrice);
                        UnitsInStock.Text = string.IsNullOrEmpty(datainfo.UnitsInStock.ToString()) ? "" : datainfo.UnitsInStock.ToString();
                        UnitsOnOrder.Text = string.IsNullOrEmpty(datainfo.UnitsOnOrder.ToString()) ? "" : datainfo.UnitsOnOrder.ToString();
                        ReorderLevel.Text = string.IsNullOrEmpty(datainfo.ReorderLevel.ToString()) ? "" : datainfo.ReorderLevel.ToString();
                        if (string.IsNullOrEmpty(datainfo.CategoryID.ToString()))
                        {
                            CategoryList.SelectedIndex = 0;
                        }
                        else
                        {
                            CategoryList.SelectedValue = datainfo.CategoryID.ToString();
                        }
                        if (string.IsNullOrEmpty(datainfo.SupplierID.ToString()))
                        {
                            SupplierList.SelectedIndex = 0;
                        }
                        else
                        {
                            SupplierList.SelectedValue = datainfo.SupplierID.ToString();
                        }
                        Discontinued.Checked = datainfo.Discontinued;
                    }

                }
                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");
                }
            }
        }
Exemple #24
0
        public ActionResult Edit1([Bind(Include = "CONO,SDATE,COSTAT,FILETYPE,FILELOC,SEALLOC,EDATE,ROWNO,STAMP")] CSCOSTAT cSCOSTAT)
        {
            if (ModelState.IsValid)
            {
                ASIDBConnection newdb = new ASIDBConnection();
                try
                {
                    string   oldKey = (string)Session["CSCOSTAT_OLDCONO"];
                    CSCOSTAT curRec = db.CSCOSTATs.Find(oldKey, cSCOSTAT.ROWNO); //allowing for key change
                    if (curRec.STAMP == cSCOSTAT.STAMP)
                    {
                        cSCOSTAT.STAMP = cSCOSTAT.STAMP + 1;

                        if (oldKey != cSCOSTAT.CONO)
                        {
                            curRec.SDATE = new DateTime(3000, 1, 2); // make sure the old previous row date gets reversed
                            UpdatePreviousRow(curRec);
                            db.CSCOSTATs.Remove(curRec);

                            int lastRowNo = 0;
                            try
                            {
                                lastRowNo = db.CSCOSTATs.Where(m => m.CONO == cSCOSTAT.CONO).Max(n => n.ROWNO);
                            }
                            catch (Exception e) { lastRowNo = -1; }
                            finally { };


                            cSCOSTAT.ROWNO = lastRowNo + 1;


                            db.CSCOSTATs.Add(cSCOSTAT);
                        }
                        else
                        {
                            db.Entry(cSCOSTAT).State = EntityState.Modified;
                        }

                        if (db.CSCOSTATs.Where(x => x.CONO == cSCOSTAT.CONO).OrderByDescending(x => x.ROWNO).Select(x => x.ROWNO).FirstOrDefault() == cSCOSTAT.ROWNO)
                        {
                            UpdateCompany(cSCOSTAT);
                        }

                        UpdatePreviousRow(cSCOSTAT); // will always do this for the current record


                        db.SaveChanges();
                        // return RedirectToAction("Details", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) });
                        //return new RedirectResult(Url.Action("Details", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) }) + "#Status");


                        int page = (int)Session["CSCOSTATPage"];
                        return(RedirectToAction("Index", new { page = page }));
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Record is modified");
                    }
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                catch (Exception e)
                {
                    ModelState.AddModelError(string.Empty, e.Message);
                }
                finally
                {
                    newdb.Dispose();
                }
            }
            ViewBag.CONO      = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSCOSTAT.CONO);
            ViewBag.COSTAT    = new SelectList(db.CSSTATs, "COSTAT", "COSTAT", cSCOSTAT.COSTAT);
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View(cSCOSTAT));
        }
        protected void UpdateProduct_Click(object sender, EventArgs e)
        {
            //if (Page.IsValid)
            //{
            //add any addition logic validation required for
            //    processing
            //in this example we will assume the supplier id
            //    and category id are required
            if (SupplierList.SelectedIndex == 0)
            {
                errormsgs.Add("Please select a supplier");
            }
            if (CategoryList.SelectedIndex == 0)
            {
                errormsgs.Add("Please select a category");
            }

            //on an update, you MUST ENSURE that the primary key value
            //   exists for use by the update
            int productid = 0;
            if (!int.TryParse(ProductID.Text.Trim(), out productid))
            {
                errormsgs.Add("Invalid or missing Product ID");
            }


            //all code behind logical validation errors are
            //    captured and reported at once
            if (errormsgs.Count() > 0)
            {
                LoadMessageDisplay(errormsgs, "alert alert-info");
            }
            else
            {
                try
                {
                    //create an instance of Product
                    Product item = new Product();
                    //collect the data from the web form and place
                    //   in the Product instance

                    //on the update, the primary identity key value
                    //   MUST ALSO be loaded to the instance
                    item.ProductID = int.Parse(ProductID.Text.Trim());

                    item.ProductName = ProductName.Text;
                    item.SupplierID = int.Parse(SupplierList.SelectedValue);
                    item.CategoryID = int.Parse(CategoryList.SelectedValue);
                    item.QuantityPerUnit = string.IsNullOrEmpty(QuantityPerUnit.Text.Trim()) ? null : QuantityPerUnit.Text.Trim();
                    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);
                    }
                    //handling of the Discontinued needs to take the current
                    //   value from the form
                    item.Discontinued = Discontinued.Checked;

                    //connect to the appropriate BLL controller
                    ProductController sysmgr = new ProductController();
                    //issue a call to the appropriate BLL controller method
                    int rowsaffected = sysmgr.Product_Update(item);
                    //Handle results
                    if (rowsaffected == 0)
                    {
                        errormsgs.Add(ProductName.Text + " has been not been updated. Search for product again.");
                        LoadMessageDisplay(errormsgs, "alert alert-warning");
                        BindProductList();
                    }
                    else
                    {
                        errormsgs.Add(ProductName.Text + " has been updated");
                        LoadMessageDisplay(errormsgs, "alert alert-success");
                        BindProductList();
                        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");
                }

            }
            //}
        }
Exemple #26
0
        public ActionResult DeleteConfirmed(string id, int row)
        {
            CSCOSTAT cSCOSTAT = db.CSCOSTATs.Find(MyHtmlHelpers.ConvertByteStrToId(id), row);

            CSCOSTAT curRec = UpdatePreviousRow(cSCOSTAT);

            if (curRec != null)
            {
                try
                {
                    if (db.CSCOSTATs.Where(x => x.CONO == cSCOSTAT.CONO).OrderByDescending(x => x.ROWNO).Select(x => x.ROWNO).FirstOrDefault() == cSCOSTAT.ROWNO)
                    {
                        UpdateCompany(curRec);
                    }
                    db.CSCOSTATs.Remove(cSCOSTAT);
                    db.SaveChanges();
                    // return RedirectToAction("Details", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) });
                    return(new RedirectResult(Url.Action("Edit", "CSCOMSTRs", new { id = MyHtmlHelpers.ConvertIdToByteStr(cSCOSTAT.CONO) }) + "#Status"));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Cannot delete the only status record");
            }

            ViewBag.COSTAT    = new SelectList(db.CSSTATs, "COSTAT", "COSTAT", cSCOSTAT.COSTAT);
            ViewBag.Title     = "Delete Company Change Status";
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View(cSCOSTAT));
        }
Exemple #27
0
        private void button6_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow dgv in dataGridView1.Rows)
            {
                if (dataGridView2.Rows.Count > 0)
                {
                    foreach (DataGridViewRow dv in dataGridView2.Rows)
                    {
                        var ems = data.foods.Find(int.Parse(dv.Cells[0].Value.ToString()));
                        try
                        {
                            data.foods.Remove(ems);
                        }
                        catch (Exception ex) { }
                    }
                }

                int rawId = int.Parse(dgv.Cells[1].Value.ToString());
                var aa    = data.foods.Where(x => x.foodid.Equals(rawId)).Count();

                if (aa > 0)
                {
                    var em = data.foods.Where(x => x.foodid.Equals(rawId)).First();
                    em.foodname    = dgv.Cells[2].Value.ToString();
                    em.description = dgv.Cells[3].Value.ToString();
                    em.price       = int.Parse(dgv.Cells[4].Value.ToString());
                    em.status      = "A";

                    try
                    {
                        data.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        UpdateException updateEx = (UpdateException)ex.InnerException;
                        SqlException    sqlEx    = (SqlException)updateEx.InnerException;

                        foreach (SqlError a in sqlEx.Errors)
                        {
                            MessageBox.Show(a.Message);
                        }
                        continue;
                    }
                }
                else
                {
                    food em = new food();
                    em.foodid      = int.Parse(dgv.Cells[1].Value.ToString());
                    em.foodname    = dgv.Cells[2].Value.ToString();
                    em.description = dgv.Cells[3].Value.ToString();
                    em.price       = int.Parse(dgv.Cells[4].Value.ToString());
                    em.status      = "A";

                    try
                    {
                        data.foods.Add(em);
                        data.SaveChanges();
                    }
                    catch (DbUpdateException ex)
                    {
                        UpdateException updateEx = (UpdateException)ex.InnerException;
                        SqlException    sqlEx    = (SqlException)updateEx.InnerException;

                        foreach (SqlError a in sqlEx.Errors)
                        {
                            MessageBox.Show(a.Message);
                        }
                        continue;
                    }
                }
            }

            MessageBox.Show("Data updated!");
            loadFood();
        }
Exemple #28
0
        public ActionResult Delete1Confirmed(string id, int row, int?page)
        {
            CSCOSTAT cSCOSTAT = db.CSCOSTATs.Find(MyHtmlHelpers.ConvertByteStrToId(id), row);

            CSCOSTAT curRec = UpdatePreviousRow(cSCOSTAT);

            if (curRec != null)
            {
                try
                {
                    if (db.CSCOSTATs.Where(x => x.CONO == cSCOSTAT.CONO).OrderByDescending(x => x.ROWNO).Select(x => x.ROWNO).FirstOrDefault() == cSCOSTAT.ROWNO)
                    {
                        UpdateCompany(curRec);
                    }

                    db.CSCOSTATs.Remove(cSCOSTAT);
                    db.SaveChanges();

                    return(RedirectToAction("Index", new { page = page }));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            //string message = string.Format("{0}:{1}",
                            //    validationErrors.Entry.Entity.ToString(),
                            //   validationError.ErrorMessage);
                            // raise a new exception nesting
                            // the current instance as InnerException
                            ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
                catch (DbUpdateException ex)
                {
                    UpdateException updateException = (UpdateException)ex.InnerException;
                    if (updateException != null)
                    {
                        if (updateException.InnerException != null)
                        {
                            var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                            foreach (var error in sqlException.Errors)
                            {
                                if (error.Message != null)
                                {
                                    ModelState.AddModelError(string.Empty, error.Message);
                                }
                            }
                        }
                        else
                        {
                            ModelState.AddModelError(string.Empty, updateException.Message);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Cannot delete the only status record");
            }

            Session["CSCOSTATPage"]     = page ?? 1;
            Session["CSCOSTAT_OLDCONO"] = cSCOSTAT.CONO; // storing the old no so that can allow change of cono
            ViewBag.CONO      = new SelectList(db.CSCOMSTRs.Select(x => new { CONO = x.CONO, CONAME = x.CONAME + "  (" + x.CONO + ")" }).OrderBy(y => y.CONAME), "CONO", "CONAME", cSCOSTAT.CONO);
            ViewBag.COSTAT    = new SelectList(db.CSSTATs, "COSTAT", "COSTAT", cSCOSTAT.COSTAT);
            ViewBag.page      = page ?? 1;
            ViewBag.Title     = "Delete Company Change Status";
            cSCOSTAT.CSCOMSTR = db.CSCOMSTRs.Find(cSCOSTAT.CONO);
            return(View("Edit1", cSCOSTAT));
        }
Exemple #29
0
        protected void UpdateProduct_Click(object sender, EventArgs e)
        {
            //ensure validation is still good
            if (Page.IsValid)
            {
                //event code validation that was not accomplished on
                //   the web form
                //examples
                //Assume that the CategoryID is required
                if (CategoryList.SelectedIndex == 0)
                {
                    errormsgs.Add("Category is required");
                }
                if (QuantityPerUnit.Text.Length > 20)
                {
                    errormsgs.Add("Quantity per Unit is limited to 20 characters");
                }

                //on updae, ensure you have your primary key value
                int productid = 0;
                if (string.IsNullOrEmpty(ProductID.Text))
                {
                    errormsgs.Add("Search for a product to update");
                }
                else if (!int.TryParse(ProductID.Text, out productid))
                {
                    errormsgs.Add("Product id is invalid");
                }
                else if (productid < 1)
                {
                    errormsgs.Add("Product id is invalid");
                }

                //check if click event validation is good
                if (errormsgs.Count > 0)
                {
                    LoadMessageDisplay(errormsgs, "alert alert-info");
                }
                else
                {
                    //assume taht the data is validate to our knowledge
                    try
                    {
                        //standard update to a database
                        //connect to the appropriate controller
                        ProductController sysmgr = new ProductController();
                        //create and load an instance of the entity record
                        //  since there was no constructor placed in the
                        //  entity, when one creaes the instance the
                        //  default system construtor will be used
                        Product item = new Product();
                        //ensure yo include the primary key
                        item.ProductID   = productid;
                        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);
                        }
                        //actually current valud of discontinued is needed
                        item.Discontinued = Discontinued.Checked;
                        //issue the BLL call
                        int rowsaffected = sysmgr.Products_Update(item);
                        //give feedback
                        if (rowsaffected > 0)
                        {
                            errormsgs.Add("Product has been updated");
                            LoadMessageDisplay(errormsgs, "alert alert-success");
                            //is there any other controls on the form that need to be refreshed
                            BindProductList(); //by default, list will be at index 0
                            ProductList.SelectedValue = ProductID.Text;
                        }
                        else
                        {
                            errormsgs.Add("Product has not been updated. Product was not found");
                            LoadMessageDisplay(errormsgs, "alert alert-info");
                            //is there any other controls on the form that need to be refreshed
                            BindProductList(); //by default, list will be at index 0

                            //optionally you could clear your fields
                        }
                    }
                    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");
                    }
                }
            }
        }
Exemple #30
0
        public ActionResult DeleteConfirmed(string id)
        {
            int  page = (int)Session["CSPRSPage"];
            CSPR cSPR = db.CSPRS.Find(MyHtmlHelpers.ConvertByteStrToId(id));

            try
            {
                db.CSPRS.Remove(cSPR);
                db.SaveChanges();

                return(RedirectToAction("Index", new { page = page }));
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        //string message = string.Format("{0}:{1}",
                        //    validationErrors.Entry.Entity.ToString(),
                        //   validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        ModelState.AddModelError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
            }
            catch (DbUpdateException ex)
            {
                UpdateException updateException = (UpdateException)ex.InnerException;
                if (updateException != null)
                {
                    if (updateException.InnerException != null)
                    {
                        var sqlException = (FirebirdSql.Data.FirebirdClient.FbException)updateException.InnerException;

                        foreach (var error in sqlException.Errors)
                        {
                            if (error.Message != null)
                            {
                                ModelState.AddModelError(string.Empty, error.Message);
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, updateException.Message);
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, updateException.Message);
                }
            }
            ViewBag.SEX       = cSPR.gender;
            ViewBag.CONSTCODE = new SelectList(db.HKCONSTs.OrderBy(x => x.CONSTCODE).Select(x => new { CONSTCODE = x.CONSTCODE, CONSTDESC = x.CONSTCODE + " | " + x.CONSTDESC + " | " + x.CONSTTYPE }), "CONSTCODE", "CONSTDESC", cSPR.CONSTCODE);
            ViewBag.PRSTITLE  = new SelectList(db.HKTITLEs, "TITLE", "TITLE", cSPR.PRSTITLE);
            ViewBag.NATION    = new SelectList(db.HKNATIONs, "NATION", "NATION", cSPR.NATION);
            ViewBag.RACE      = new SelectList(db.HKRACEs, "RACE", "RACE", cSPR.RACE);
            ViewBag.CTRYINC   = new SelectList(db.HKCTRies, "CTRYCODE", "CTRYDESC", cSPR.CTRYINC);
            ViewBag.Title     = "Delete Entity ";
            ViewBag.page      = page;
            return(View("Edit", cSPR));
        }