Ejemplo n.º 1
0
 public TblBrandBudgetDetail SaveBrandBudget(TblBrandBudgetDetail details, int userIserial)
 {
     using (var db = new WorkFlowManagerDBEntities())
     {
         var ExistingDetail = db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial);
         if (ExistingDetail == null)
         {
             db.TblBrandBudgetDetails.AddObject(details);
             db.SaveChanges();
         }
         else
         {
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).TblLkpDirection         = details.TblLkpDirection;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).TblStyleCategory        = details.TblStyleCategory;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).TblFamily               = details.TblFamily;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).TblSalesOrderColorTheme = details.TblSalesOrderColorTheme;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).PaymentDate             = details.PaymentDate;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).Amount     = details.Amount;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).Qty        = details.Qty;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).NoOfStyles = details.NoOfStyles;
             db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial).NoOfStyles = details.NoOfStyles;
             db.SaveChanges();
         }
         return(db.TblBrandBudgetDetails.FirstOrDefault(x => x.Iserial == details.Iserial));
     }
 }
Ejemplo n.º 2
0
 public TblBrandBudgetDetail UpdateOrInsertTblBrandBudgetDetail(TblBrandBudgetDetail newRow, bool save, int index, out int outindex, int userIserial)
 {
     using (var db = new WorkFlowManagerDBEntities())
     {
         outindex = index;
         if (save)
         {
             db.TblBrandBudgetDetails.AddObject(newRow);
             db.SaveChanges();
             if (newRow.TblBrandBudgetHeader1 != null)
             {
                 newRow.TblBrandBudgetHeader1.LastUpdatedDate = DateTime.Now;
                 newRow.TblBrandBudgetHeader1.CreatedBy       = userIserial;
             }
             else
             {
                 var header =
                     db.TblBrandBudgetHeaders.FirstOrDefault(x => x.Iserial == newRow.TblBrandBudgetHeader);
                 if (header != null)
                 {
                     header.LastUpdatedDate = DateTime.Now;
                     header.LastUpdatedBy   = userIserial;
                 }
             }
         }
         else
         {
             var oldRow = (from e in db.TblBrandBudgetDetails
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 var temp = GenericUpdate(oldRow, newRow, db);
                 if (temp.Any())
                 {
                     var header =
                         db.TblBrandBudgetHeaders.FirstOrDefault(x => x.Iserial == newRow.TblBrandBudgetHeader);
                     if (header != null)
                     {
                         header.LastUpdatedDate = DateTime.Now;
                         header.LastUpdatedBy   = userIserial;
                     }
                 }
             }
         }
         db.SaveChanges();
         return(newRow);
     }
 }
Ejemplo n.º 3
0
        private int DeleteTblBrandBudgetDetail(TblBrandBudgetDetail row)
        {
            using (var db = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in db.TblBrandBudgetDetails
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    db.DeleteObject(oldRow);
                }

                db.SaveChanges();
            }
            return(row.Iserial);
        }
Ejemplo n.º 4
0
        public void SaveDetailRow()
        {
            foreach (var row in TransactionHeader.DetailsList.Where(x => x.Iserial != -1))
            {
                var  valiationCollection = new List <ValidationResult>();
                bool isvalid             = Validator.TryValidateObject(row,
                                                                       new ValidationContext(row, null, null), valiationCollection, true);
                var  valiationCollectionHeader = new List <ValidationResult>();
                bool isvalidHeader             = Validator.TryValidateObject(TransactionHeader,
                                                                             new ValidationContext(TransactionHeader, null, null), valiationCollectionHeader, true);

                TransactionHeader.TransactionType = TransactionType;
                if (TransactionHeader.DetailsList.Where(x => x.Iserial != -1).Sum(x => x.Amount) > TransactionHeader.Amount)
                {
                    MessageBox.Show("Amount of the Detail Exceeded The Brand Amount");
                    row.Amount = 0;
                    isvalid    = false;
                }

                if (TransactionType == 1)
                {
                    if (TransactionHeader.DetailsList.Count(x => x.TblFamily == row.TblFamily) > 1)
                    {
                        MessageBox.Show("Cannot Duplicate Family");
                        row.FamilyPerRow = null;
                        row.TblFamily    = null;
                        isvalid          = false;
                    }
                }

                if (isvalid)
                {
                    var data = new TblBrandBudgetDetail();
                    data.InjectFrom(row);
                    row.TblBrandBudgetHeader = TransactionHeader.Iserial;
                    if (row.TblBrandBudgetHeader == 0)
                    {
                        data.TblBrandBudgetHeader1 =
                            (TblBrandBudgetHeader) new TblBrandBudgetHeader().InjectFrom(TransactionHeader);
                    }
                    bool save = row.Iserial == 0;
                    if (save)
                    {
                        if (AllowAdd)
                        {
                            Loading = true;
                            Client.UpdateOrInsertTblBrandBudgetDetailAsync(data, true,
                                                                           TransactionHeader.DetailsList.IndexOf(row), LoggedUserInfo.Iserial);
                        }
                        else
                        {
                            MessageBox.Show("You are Not Allowed to Add");
                        }
                    }
                    else
                    {
                        if (AllowUpdate)
                        {
                            Loading = true;
                            Client.UpdateOrInsertTblBrandBudgetDetailAsync(data, false,
                                                                           TransactionHeader.DetailsList.IndexOf(row), LoggedUserInfo.Iserial);
                        }
                        else
                        {
                            MessageBox.Show("You are Not Allowed to Update");
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public BrandBudgetViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                TransactionHeader = new TblBrandBudgetsHeaderViewModel();
                GetItemPermissions(PermissionItemName.BrandBudget.ToString());

                MainRowList        = new SortableCollectionView <TblBrandBudgetsHeaderViewModel>();
                SelectedDetailRows = new ObservableCollection <TblBrandBudgetDetailViewModel>();
                SelectedDetailRow  = new TblBrandBudgetDetailViewModel();
                TransactionHeader.PropertyChanged += (sender, sv) =>
                {
                    if (sv.PropertyName == "Brand")
                    {
                        Brandsection.Clear();
                        lkpClient.GetTblBrandSectionLinkAsync(TransactionHeader.Brand, LoggedUserInfo.Iserial);
                    }
                    else if (sv.PropertyName == "TblLkpBrandSection")
                    {
                        // GetFamilyLink();
                        TransactionHeader.DirectionList.Clear();
                        GetDirectionLink();
                    }

                    else if (sv.PropertyName == "TblLkpDirection")
                    {
                        TransactionHeader.StyleCategoryList.Clear();
                        GetStyleCategoryLink();
                    }


                    DataGridName = "MainGrid";
                };

                var factorGroupClient = new CRUD_ManagerServiceClient();
                factorGroupClient.GetGenericCompleted += (s, sv) =>
                {
                    FactoryGroupList = sv.Result;
                };
                factorGroupClient.GetGenericAsync("TblFactoryGroup", "%%", "%%", "%%", "Iserial", "ASC");

                //lkpClient.GetTblFamilyLinkCompleted += (s, sv) =>
                //{
                //    foreach (var row in sv.Result)
                //    {
                //        if (TransactionHeader.FamilyList != null && (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial)))
                //        {
                //            TransactionHeader.FamilyList.Add( new TblFamily().InjectFrom( row.TblFamily1) as TblFamily);
                //        }
                //    }
                //};

                lkpClient.FamilyCategory_GetTblFamilyCategoryLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.FamilyList != null && (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial)))
                        {
                            TransactionHeader.FamilyList.Add(new TblFamily().InjectFrom(row.TblFamily1) as TblFamily);
                        }
                    }
                };


                lkpClient.GetTblDirectionLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.DirectionList != null && (TransactionHeader != null && TransactionHeader.DirectionList.All(x => x.Iserial != row.TblLkpDirection1.Iserial)))
                        {
                            TransactionHeader.DirectionList.Add(new TblLkpDirection().InjectFrom(row.TblLkpDirection1) as TblLkpDirection);
                        }
                    }
                };

                lkpClient.FamilyCategory_GetTblCategoryLinkCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        if (TransactionHeader.StyleCategoryList != null && (TransactionHeader != null && TransactionHeader.StyleCategoryList.All(x => x.Iserial != row.TblStyleCategory1.Iserial)))
                        {
                            TransactionHeader.StyleCategoryList.Add(new TblStyleCategory().InjectFrom(row.TblStyleCategory1) as TblStyleCategory);
                        }
                    }
                };


                //Client.GetTblSalesOrderColorThemeCompleted += (s, sv) =>
                //{
                //    foreach (var row in sv.Result)
                //    {
                //        if (TransactionHeader.ThemeList != null && (TransactionHeader != null && TransactionHeader.ThemeList.All(x => x.Iserial != row.Iserial)))
                //        {
                //            TransactionHeader.ThemeList.Add(row);
                //        }
                //    }
                //};
                Client.GetAllBrandsCompleted += (s, ev) =>
                {
                    Brands = ev.Result;
                };

                Client.GetAllBrandsAsync(LoggedUserInfo.Iserial);

                Client.GetAllSeasonsCompleted += (s, ev) =>
                {
                    Seasons = ev.Result;
                };
                Client.GetAllSeasonsAsync();

                lkpClient.GetTblBrandSectionLinkCompleted += (s, ev) =>
                {
                    foreach (var row in ev.Result)
                    {
                        if (Brandsection.All(x => x.Iserial != row.TblLkpBrandSection))
                        {
                            Brandsection.Add(row.TblLkpBrandSection1);
                        }
                    }
                };

                Client.DeleteTblBrandBudgetDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = TransactionHeader.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        TransactionHeader.DetailsList.Remove(oldrow);
                    }
                };

                Client.UpdateOrInsertTblBrandBudgetDetailCompleted += (x, y) =>
                {
                    var savedRow = (TblBrandBudgetDetailViewModel)TransactionHeader.DetailsList.GetItemAt(y.outindex);

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(y.Result);
                        if (TransactionHeader.Iserial == 0)
                        {
                            TransactionHeader.Iserial = y.Result.TblBrandBudgetHeader;
                        }
                    }
                };
                Client.GetTblBrandBudgetDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new TblBrandBudgetDetailViewModel();
                        newrow.InjectFrom(row);

                        if (row.TblFamily1 != null)
                        {
                            newrow.FamilyPerRow = row.TblFamily1;

                            if (TransactionHeader != null && TransactionHeader.FamilyList.All(x => x.Iserial != row.TblFamily1.Iserial))
                            {
                                TransactionHeader.FamilyList.Add(newrow.FamilyPerRow);
                            }
                        }

                        if (row.TblLkpDirection1 != null)
                        {
                            newrow.DirectionPerRow = row.TblLkpDirection1;

                            if (TransactionHeader != null && TransactionHeader.DirectionList.All(x => x.Iserial != row.TblLkpDirection1.Iserial))
                            {
                                TransactionHeader.DirectionList.Add(newrow.DirectionPerRow);
                            }
                        }

                        if (row.TblStyleCategory1 != null)
                        {
                            newrow.StyleCategoryPerRow = row.TblStyleCategory1;

                            if (TransactionHeader != null && TransactionHeader.StyleCategoryList.All(x => x.Iserial != row.TblStyleCategory1.Iserial))
                            {
                                TransactionHeader.StyleCategoryList.Add(newrow.StyleCategoryPerRow);
                            }
                        }
                        //if (row.TblSalesOrderColorTheme1 != null)
                        //{
                        //    newrow.ThemePerRow = row.TblSalesOrderColorTheme1;
                        //    if (TransactionHeader != null && TransactionHeader.ThemeList.All(x => x.Iserial != row.TblSalesOrderColorTheme))
                        //    {
                        //        TransactionHeader.ThemeList.Add(newrow.ThemePerRow);
                        //    }
                        //}

                        newrow.FactoryGroupPerRow = new GenericTable();
                        if (row.TblFactoryGroup1 != null)
                        {
                            newrow.FactoryGroupPerRow.InjectFrom(row.TblFactoryGroup1);
                        }
                        TransactionHeader.DetailsList.Add(newrow);
                    }
                    TransactionHeader.AddTotalRow();
                };

                Client.GetTblBrandBudgetHeaderCompleted += (y, v) =>
                {
                    foreach (var row in v.Result)
                    {
                        Loading = false;
                        var newrow = new TblBrandBudgetsHeaderViewModel();
                        newrow.InjectFrom(row);
                        newrow.BrandSectionPerRow = row.TblLkpBrandSection1;
                        newrow.SeasonPerRow       = row.TblLkpSeason1;
                        MainRowList.Add(newrow);
                    }
                };

                Client.UpdateOrInsertTblBrandBudgetHeaderCompleted += (s, x) =>
                {
                    if (x.Error == null)
                    {
                        TransactionHeader.InjectFrom(x.Result);
                        try
                        {
                            foreach (var item in TransactionHeader.DetailsList)
                            {
                                item.TblBrandBudgetHeader = x.Result.Iserial;
                                //    Client.UpdateOrInsertTblBrandBudgetDetailAsync(item, true,
                                //     LoggedUserInfo.Iserial);

                                TblBrandBudgetDetail myitem = new TblBrandBudgetDetail();
                                myitem.Amount     = item.Amount;
                                myitem.NoOfColors = item.NoOfColors;
                                myitem.NoOfStyles = item.NoOfStyles;
                                myitem.Retail     = item.Retail;
                                //   myitem.TblSalesOrderColorTheme = item.TblSalesOrderColorTheme;
                                //  myitem.PaymentDate = item.PaymentDate;
                                myitem.Qty = item.Qty;
                                myitem.TblBrandBudgetHeader = x.Result.Iserial;
                                myitem.TblFamily            = item.TblFamily;
                                myitem.TblLkpDirection      = item.TblLkpDirection;
                                myitem.TblStyleCategory     = item.TblStyleCategory;

                                Client.SaveBrandBudgetAsync(myitem, LoggedUserInfo.Iserial);
                            }
                            MessageBox.Show("All items have been saved successfully.", "Success", MessageBoxButton.OK);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Couldn't save listed items..", "Failed", MessageBoxButton.OK);
                        }
                    }
                    else
                    {
                        MessageBox.Show(x.Error.Message);
                    }
                    Loading = false;

                    //TransactionHeader.InjectFrom(x.Result);
                };
                Client.DeleteTblBrandBudgetHeaderCompleted += (w, k) =>
                {
                    Loading = false;
                    TransactionHeader.InjectFrom(new TblBrandBudgetsHeaderViewModel());
                };
            }
        }