Example #1
0
        /// <summary>
        /// delete the sales order from the database.  This method is invoked by the DeleteSOCommand.
        /// </summary>
        public void DeleteSO(string SONumber)
        {
            MessageBoxResult messageBoxResult =
                System.Windows.MessageBox.Show("Are you sure to delete sales order # " + SONumber + " ?", "MRP4ME - Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                using (var dbContext = new MRP4MEEntities())
                {
                    sales_order item = Salesorders.FirstOrDefault(x => x.so_number == SONumber);
                    dbContext.sales_order.Attach(item);
                    dbContext.sales_order.Remove(item);
                    dbContext.SaveChanges();
                    dbContext.Entry(item).State = System.Data.Entity.EntityState.Detached;
                    Salesorders.Remove(item);
                    NotifyPropertyChanged("Salesorders");
                }
            }
        }
        /// <summary>
        /// Saves the SO to the DB.  This method is invoked by the SaveCommand.
        /// </summary>
        public void Save()
        {
            try
            {
                sales_order _sales_order;

                using (var dbContext = new MRP4MEEntities())
                {
                    _sales_order = dbContext.sales_order.Find(salesorder.so_number);

                    if (_sales_order != null)
                    { //check for duplicate sales order number when new SO
                        if (isNewSO)
                        {
                            throw new DbUpdateException();
                        }
                    }
                    else
                    { //if sales order is null then it is new sales order
                        _sales_order = new sales_order();
                    }

                    DateTime dateValue = DateTime.Parse(this.RequiredDate.ToString());
                    _sales_order.customer_name = salesorder.customer_name;
                    _sales_order.required_date = DateTime.Parse(dateValue.ToString("yyyy/MM/dd"));
                    _sales_order.so_number     = salesorder.so_number;
                    _sales_order.item_code     = salesorder.item_code;
                    _sales_order.name          = salesorder.name;
                    _sales_order.unit          = salesorder.unit;
                    _sales_order.unit_cost     = Convert.ToDecimal(salesorder.unit_cost);
                    _sales_order.description   = salesorder.description;
                    _sales_order.quantity      = Int32.Parse(salesorder.quantity);
                    if (!String.IsNullOrEmpty(salesorder.quantity_received))
                    {
                        _sales_order.quantity_received = Int32.Parse(salesorder.quantity_received);
                    }

                    if (!String.IsNullOrEmpty(salesorder.back_ordered))
                    {
                        _sales_order.back_ordered = Int32.Parse(salesorder.back_ordered);

                        if (String.IsNullOrEmpty(salesorder.quantity_received))
                        {
                            _sales_order.quantity_received = _sales_order.quantity - _sales_order.back_ordered;
                        }
                    }


                    _sales_order.attachment   = salesorder.attachment;
                    _sales_order.upload_image = salesorder.upload_image;
                    _sales_order.user         = salesorder.user;
                    _sales_order.level        = 0;

                    if (isNewSO)
                    {
                        dbContext.sales_order.Add(_sales_order);
                        dbContext.SaveChanges();
                        dbContext.Entry(_sales_order).State = EntityState.Detached;
                    }
                    else
                    {
                        dbContext.SaveChanges();
                        dbContext.Entry(_sales_order).State = EntityState.Modified;
                        dbContext.Entry(_sales_order).State = EntityState.Detached;
                    }
                }
                ClearForm();

                MessageBox.Show("Sales Order successfully saved.", "MRP4ME");
                //NotifyPropertyChanged("SO");
            }
            catch (DbUpdateException ex)
            {
                //MessageBox.Show("SO Number already exist!" , "MRP4ME");
                AddError(new ValidationError("SONumber", Constraint_Mandatory, " SO Number already exist!"));
                NotifyPropertyChanged("SONumber");
                Tracer.LogUserDefinedValidation("DbUpdateException. " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Sales Order not saved, please verify data and save again." + ex.Message, "MRP4ME");
            }
        }
Example #3
0
        /// <summary>
        /// Saves the BOM to the DB.  This method is invoked by the SaveCommand.
        /// </summary>
        public void Save()
        {
            try
            {
                bom_table _bom;

                using (var dbContext = new MRP4MEEntities())
                {
                    _bom = dbContext.bom_table.Find(bomForDB.bom_id);

                    if (_bom != null)
                    { //check for duplicate Item Number when new BOM
                        if (isNewBOM)
                        {
                            throw new DbUpdateException();
                        }
                    }
                    else
                    { //if BOM is null then it is new BOM
                        _bom = new bom_table();
                    }

                    DateTime dateValueEffFrom = DateTime.Parse(this.EffectiveFrom.ToString());
                    DateTime dateValueEffTo   = DateTime.Parse(this.EffectiveThrough.ToString());
                    _bom.item_number           = bomForDB.item_number;
                    _bom.item_code             = bomForDB.item_code;
                    _bom.version               = Int32.Parse(bomForDB.version);
                    _bom.component             = bomForDB.component;
                    _bom.component_description = bomForDB.component_description;
                    _bom.type                     = bomForDB.type;
                    _bom.quantity_per             = Convert.ToSingle(bomForDB.quantity_per);
                    _bom.unit_of_measure          = bomForDB.unit_of_measure;
                    _bom.effective_from           = DateTime.Parse(dateValueEffFrom.ToString("yyyy/MM/dd"));
                    _bom.effective_through        = DateTime.Parse(dateValueEffTo.ToString("yyyy/MM/dd"));
                    _bom.engineering_change_order = this.EngineeringChangeOrder == "Yes"? true : false;
                    _bom.cost_of_unit_of_measure  = Convert.ToDecimal(bomForDB.cost_of_unit_of_measure);
                    _bom.bom_cost                 = Convert.ToDecimal(bomForDB.bom_cost);
                    _bom.scrap_percent            = Convert.ToDecimal(bomForDB.scrap_percent);
                    _bom.scrap_cost               = Convert.ToDecimal(bomForDB.scrap_cost);
                    _bom.extended_cost            = Convert.ToDecimal(bomForDB.extended_cost);

                    if (isNewBOM)
                    {
                        dbContext.bom_table.Add(_bom);
                        dbContext.SaveChanges();
                        dbContext.Entry(_bom).State = EntityState.Detached;
                    }
                    else
                    {
                        dbContext.SaveChanges();
                        dbContext.Entry(_bom).State = EntityState.Modified;
                        dbContext.Entry(_bom).State = EntityState.Detached;
                    }
                }
                ClearForm();

                MessageBox.Show("BOM successfully saved.", "MRP4ME");
            }
            catch (DbUpdateException ex)
            {
                AddError(new ValidationError("BOM", Constraint_Mandatory, " Item Number already exist!"));
                NotifyPropertyChanged("ItemNumber");
                Tracer.LogUserDefinedValidation("DbUpdateException. " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("BOM not saved, please verify data and save again." + ex.Message, "MRP4ME");
            }
        }