Esempio n. 1
0
        private void SaveAccessories()
        {
            var client    = new _Proxy.CRUD_ManagerServiceClient();
            var headerRow = new _Proxy.tbl_AccessoryAttributesHeader();

            headerRow.InjectFrom(SelectedMainRow);

            var detailsList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>();

            GenericMapper.InjectFromObCollection(detailsList, AccDetailsList);


            var valiationCollection = new List <ValidationResult>();

            var isvalid = Validator.TryValidateObject(SelectedMainRow,
                                                      new ValidationContext(SelectedMainRow, null, null), valiationCollection, true);

            if (!isvalid)
            {
                MessageBox.Show("Data IS not Valid");
                return;
            }


            if (SelectedMainRow.ObjStatus.IsNew)
            {
                client.AddAllNewAccessoriesAttributesCompleted += (s, sv)
                                                                  =>
                {
                    MessageBox.Show(sv.Error == null ? strings.SavedMessage : strings.FailSavingMessage);
                    SelectedMainRow.InjectFrom(sv.Result);
                    SelectedMainRow.ObjStatus.IsNew         = false;
                    SelectedMainRow.ObjStatus.IsSavedDBItem = true;

                    AccDetailsList = new SortableCollectionView <AccessoryAttributesDetailsViewModel>();


                    foreach (var row in sv.Result.tbl_AccessoryAttributesDetails)
                    {
                        var newrow = new AccessoryAttributesDetailsViewModel
                        {
                            ObjStatus = { IsNew = false, IsSavedDBItem = true }
                        };
                        newrow.InjectFrom(row);
                        AccDetailsList.Add(newrow);
                    }
                };
                //  if (AllowAdd)
                //        {
                client
                .AddAllNewAccessoriesAttributesAsync
                    (headerRow
                    , detailsList, SelectedMainRow.IsSizeIncludedInHeader, LoggedUserInfo.Iserial);
                //       }
                //      else
                //   {
                //         MessageBox.Show("You do not have the permission to add a new item!");
                //    }
            }
            else if (SelectedMainRow.ObjStatus.IsSavedDBItem)
            {
                client.UpdateAccessoriesAttributesCompleted += (s, e) =>
                {
                    MessageBox.Show(e.Error == null ? strings.SavedMessage : strings.FailSavingMessage);
                    SelectedMainRow.InjectFrom(e.Result);
                    SelectedMainRow.ObjStatus.IsNew         = false;
                    SelectedMainRow.ObjStatus.IsSavedDBItem = true;

                    AccDetailsList = new SortableCollectionView <AccessoryAttributesDetailsViewModel>();

                    foreach (var row in e.Result.tbl_AccessoryAttributesDetails)
                    {
                        var newrow = new AccessoryAttributesDetailsViewModel
                        {
                            ObjStatus = { IsNew = false, IsSavedDBItem = true }
                        };
                        newrow.InjectFrom(row);
                        AccDetailsList.Add(newrow);
                    }
                }
                ;
                //     if (AllowUpdate)
                //     {
                var detailsNewList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>();
                GenericMapper.InjectFromObCollection(detailsNewList, AccDetailsList.Where(x => x.ObjStatus.IsNew));

                var detailsUpdatedList = new ObservableCollection <_Proxy.tbl_AccessoryAttributesDetails>();
                GenericMapper.InjectFromObCollection(detailsUpdatedList, AccDetailsList.Where(x => x.ObjStatus.IsSavedDBItem));

                client
                .UpdateAccessoriesAttributesAsync
                    (headerRow,
                    detailsNewList,
                    detailsUpdatedList, LoggedUserInfo.Iserial);
                //   }
                //    else
                //    {
                //        MessageBox.Show("You do not have the update permission");
                //   }
            }
        }
        public DyeingOrderInvoiceViewModel() : base(PermissionItemName.DyeingOrderInvoice)
        {
            GetItemPermissions(PermissionItemName.DyeingOrderInvoice.ToString());
            //PermissionItemName.dyeing
            DyeingServiceClient.PostDyeingOrderInvoiceCompleted += (s, sv) =>
            {
                if (sv.Result != null)
                {
                    SelectedMainRow.InjectFrom(sv.Result);
                }
                SelectedMainRow.VisPosted = false;
                MessageBox.Show("Posted Completed");
            };
            DyeingServiceClient.DeleteDyeingOrderInvoiceHeaderCompleted += (s, ev) =>
            {
                if (ev.Error != null)
                {
                    MessageBox.Show(ev.Error.Message);
                }
                var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                if (oldrow != null)
                {
                    MainRowList.Remove(oldrow);
                }
            };

            MiscValueTypeList = new ObservableCollection <GenericTable>
            {
                new GenericTable {
                    Iserial = 0, Code = "%", Ename = "%", Aname = "%"
                },
                new GenericTable {
                    Iserial = 1, Code = "Value", Ename = "Value", Aname = "Value"
                }
            };

            var currencyClient = new GlService.GlServiceClient();

            currencyClient.GetGenericCompleted += (s, sv) =>
            {
                CurrencyList = new ObservableCollection <CRUDManagerService.GenericTable>();
                foreach (var item in sv.Result)
                {
                    CurrencyList.Add(new CRUDManagerService.GenericTable().InjectFrom(item) as CRUDManagerService.GenericTable);
                }
            };
            currencyClient.GetGenericAsync("TblCurrency", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname);

            var journalAccountTypeClient = new GlService.GlServiceClient();

            journalAccountTypeClient.GetGenericCompleted += (s, sv) =>
            {
                JournalAccountTypeList = sv.Result;
            };
            journalAccountTypeClient.GetGenericAsync("TblJournalAccountType", "%%", "%%", "%%", "Iserial", "ASC", LoggedUserInfo.DatabasEname);


            PurchasePlanClient.GetTblMarkupProdAsync(0, int.MaxValue, "it.Iserial", null, null, LoggedUserInfo.DatabasEname);

            PurchasePlanClient.GetTblMarkupProdCompleted += (s, sv) =>
            {
                MarkupList = new ObservableCollection <TblMarkupProd>();
                foreach (var item in sv.Result)
                {
                    MarkupList.Add(new TblMarkupProd().InjectFrom(item) as TblMarkupProd);
                }

                // MarkupList = sv.Result;
            };



            SelectedMainRow = new TblDyeingOrderInvoiceHeaderViewModel {
                DocDate = DateTime.Now
            };

            DyeingServiceClient.UpdateOrInsertDyeingOrderInvoiceHeaderCompleted += (s, sv) =>
            {
                if (sv.Error != null)
                {
                    MessageBox.Show(sv.Error.Message);
                }
                try
                {
                    SelectedMainRow.InjectFrom(sv.Result);

                    if (SelectedMainRow.Status == 0)
                    {
                        SelectedMainRow.VisPosted = true;
                    }
                    else
                    {
                        SelectedMainRow.VisPosted = false;
                    }
                }

                catch (Exception)
                {
                }
                Loading = false;
                if (OpenMisc)
                {
                    new MarkupTransProdChildWindow(this).Show();
                    OpenMisc = false;
                }
            };

            PurchasePlanClient.UpdateOrInsertDyeingOrderInvoiceMarkupTransProdsCompleted += (s, x) =>
            {
                var markup = new TblMarkupProd();
                try
                {
                    var row = SelectedMainRow.MarkUpTransList.ElementAt(x.outindex);
                    if (row != null)
                    {
                        markup = row.TblMarkupProd1;
                    }
                    if (x.Result.Iserial == -1)
                    {
                        MessageBox.Show("This Markup Is Not Linked To Account");
                        row.TblMarkupProd1 = null;
                    }
                    else
                    {
                        SelectedMainRow.MarkUpTransList.ElementAt(x.outindex).InjectFrom(x.Result);
                        if (row != null)
                        {
                            row.TblMarkupProd1 = markup;
                        }
                    }
                }
                catch (Exception)
                {
                }

                Loading = false;
            };
            DyeingServiceClient.GetDyeingOrderInvoiceHeaderCompleted += (s, sv) =>
            {
                Loading = false;
                MainRowList.Clear();
                foreach (var variable in sv.Result.ToList())
                {
                    var newvendor = new Vendor();
                    newvendor.InjectFrom(sv.Vendors.FirstOrDefault(w => w.vendor_code == variable.Vendor));

                    var newrow = new TblDyeingOrderInvoiceHeaderViewModel();
                    newrow.InjectFrom(variable);
                    newrow.VendorPerRow = newvendor;
                    if (newrow.Status == 0)
                    {
                        newrow.VisPosted = true;
                    }
                    newrow.CurrencyPerRow = new GenericTable();
                    newrow.CurrencyPerRow.InjectFrom(CurrencyList.FirstOrDefault(w => w.Iserial == variable.TblCurrency));
                    newrow.TblCurrency = variable.TblCurrency;
                    MainRowList.Add(newrow);
                }
            };

            DyeingServiceClient.GetDyeingOrderInvoiceDetailCompleted += (s, sv) =>
            {
                foreach (var variable in sv.Result.ToList())
                {
                    var newrow = new TblDyeingOrderInvoiceDetailViewModel();
                    newrow.InjectFrom(variable);
                    newrow.ServicePerRow       = new TblService();
                    newrow.ColorPerRow         = new TblColor();
                    newrow.ColorPerRow.Code    = variable.TblColor1.Code;
                    newrow.ServicePerRow.Code  = variable.TblService1.Code;
                    newrow.ServicePerRow.Ename = variable.TblService1.Ename;
                    TransactionDetails.Add(newrow);
                }
            };
            DyeingServiceClient.SearchDyeingOrderInvoiceCompleted += (s, sv) =>
            {
                TransactionDetails.Clear();
                foreach (var variable in sv.Result.ToList())
                {
                    var newrow = new TblDyeingOrderInvoiceDetailViewModel();
                    newrow.InjectFrom(variable);
                    newrow.ServicePerRow       = new TblService();
                    newrow.ColorPerRow         = new TblColor();
                    newrow.ColorPerRow.Code    = variable.ColorCode;
                    newrow.ServicePerRow.Code  = variable.ServiceCode;
                    newrow.ServicePerRow.Ename = variable.ServiceName;
                    newrow.SupplierInv         = variable.SupplierInv;
                    TransactionDetails.Add(newrow);
                }
            };

            PurchasePlanClient.DyeingOrderInvoiceMarkupTransProdCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    var newrow = new TblMarkupTranProdViewModel();
                    newrow.InjectFrom(row);
                    newrow.CurrencyPerRow = new GenericTable();
                    newrow.CurrencyPerRow.InjectFrom(CurrencyList.FirstOrDefault(w => w.Iserial == row.TblCurrency));
                    newrow.TblCurrency    = row.TblCurrency;
                    newrow.TblMarkupProd1 = new TblMarkupProd();
                    newrow.TblMarkupProd1.InjectFrom(MarkupList.FirstOrDefault(w => w.Iserial == row.TblMarkupProd));
                    newrow.TblMarkupProd            = row.TblMarkupProd;
                    newrow.JournalAccountTypePerRow = JournalAccountTypeList.FirstOrDefault(w => w.Iserial == newrow.TblJournalAccountType);
                    newrow.EntityPerRow             = new GlService.Entity().InjectFrom(sv.entityList.FirstOrDefault(w => w.Iserial == row.EntityAccount && w.TblJournalAccountType == row.TblJournalAccountType)) as GlService.Entity;
                    newrow.TblJournalAccountType    = row.TblJournalAccountType;
                    newrow.EntityAccount            = row.EntityAccount;
                    SelectedMainRow.MarkUpTransList.Add(newrow);
                }

                Loading = false;

                if (SelectedMainRow.MarkUpTransList.Count == 0)
                {
                    AddNewMarkUpRow(false, true);
                }
            };
        }
Esempio n. 3
0
        public TradeAgreementViewModel() : base(PermissionItemName.TradeAgreementFabricView)
        {
            // ده هيحتاج تعديل
            productionServiceClient.GetTblTradeAgreementDetailListFabricViewCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    var newrow = new TradeAgreementDetailModel();
                    newrow.TradeAgreementTransactionIserial = SelectedMainRow.Iserial;
                    newrow.HeaderIserial = row.TblTradeAgreementHeader;
                    newrow.ColorPerRow   = new CRUDManagerService.TblColor();
                    if (row.TblColor1 != null)
                    {
                        newrow.ColorPerRow.InjectFrom(row.TblColor1);
                    }
                    newrow.ItemPerRow = new CRUDManagerService.ItemsDto();
                    newrow.ItemPerRow.InjectFrom(sv.itemsList.SingleOrDefault(x => x.Iserial == row.ItemCode && x.ItemGroup == row.ItemType));
                    newrow.ItemType     = row.ItemType;
                    newrow.VendorPerRow = new CRUDManagerService.Vendor {
                        vendor_code = row.TblTradeAgreementHeader1.Vendor
                    };
                    newrow.VendorPurchaseGroupPerRow = new CRUDManagerService.GenericTable();
                    newrow.VendorPerRow.InjectFrom(sv.VendorList.FirstOrDefault(x => x.vendor_code == row.TblTradeAgreementHeader1.Vendor));
                    if (row.TblVendorPurchaseGroup1 != null)
                    {
                        newrow.VendorPurchaseGroupPerRow.InjectFrom(row.TblVendorPurchaseGroup1);
                    }
                    newrow.TradeAgreementTransactionIserial = row.TblTradeAgreementHeader1.TblTradeAgreementTransaction.Value;
                    newrow.HeaderIserial = row.TblTradeAgreementHeader;
                    newrow.InjectFrom(row);
                    SelectedMainRow.DetailsList.Insert(0, newrow);
                }

                Loading = false;

                if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count == 0)
                {
                    AddNewDetailRow(false);
                }
                if (Export)
                {
                    Export = false;
                    ExportGrid.ExportExcel("TradeAgreement");
                }
            }
            ;
            calculationClient.GetGenericCompleted += (s, sv) =>
            {
                VendorPurchaseGroupList = sv.Result;
            };

            Client.GetAxCurrencyAsync("CCM");
            Client.GetAxCurrencyCompleted += (s, sv) =>
            {
                AxCurrencyList = sv.Result;
            };
            Client.SearchForColorCompleted += (s, sv) =>
            {
                if (sv.Error != null)
                {
                    return;
                }

                SelectedDetailRow.Colors = sv.Result;
            };

            var currentUi = Thread.CurrentThread.CurrentUICulture;

            productionServiceClient.GetTblTradeAgreementDetailListCompleted += (d, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    var newrow = new TradeAgreementDetailModel();
                    newrow.InjectFrom(row);
                    newrow.HeaderIserial = row.TblTradeAgreementHeader;
                    newrow.TradeAgreementTransactionIserial = SelectedMainRow.Iserial;
                    newrow.ColorPerRow = new CRUDManagerService.TblColor();
                    if (row.TblColor1 != null)
                    {
                        newrow.ColorPerRow.InjectFrom(row.TblColor1);
                    }
                    newrow.TblColor   = row.TblColor;
                    newrow.ItemPerRow = new CRUDManagerService.ItemsDto();
                    var itemsDto = sv.itemsList.SingleOrDefault(x => x.Iserial == row.ItemCode && x.ItemGroup == row.ItemType);
                    if (itemsDto != null)
                    {
                        newrow.ItemPerRow.InjectFrom(itemsDto);
                    }
                    newrow.ItemCode = row.ItemCode;
                    newrow.ItemType = row.ItemType;
                    newrow.FromDate = row.TblTradeAgreementHeader1.FromDate;
                    newrow.ToDate   = row.TblTradeAgreementHeader1.ToDate;
                    newrow.VendorPurchaseGroupPerRow = VendorPurchaseGroupList.FirstOrDefault(vpg => vpg.Iserial == newrow.TblVendorPurchaseGroup);
                    newrow.VendorPerRow = new CRUDManagerService.Vendor();
                    newrow.VendorPerRow.InjectFrom(sv.vendorsList.FirstOrDefault(v => v.vendor_code == row.TblTradeAgreementHeader1.Vendor));
                    newrow.Vendor = row.TblTradeAgreementHeader1.Vendor;
                    SelectedMainRow.DetailsList.Add(newrow);
                }

                Loading         = false;
                DetailFullCount = sv.fullCount;
                if (DetailFullCount == 0 && SelectedMainRow.DetailsList.Count == 0)
                {
                    AddNewDetailRow(false);
                }
            };

            productionServiceClient.UpdateOrInsertTblTradeAgreementDetailCompleted += (s, x) =>
            {
                var savedRow = SelectedMainRow.DetailsList.ElementAtOrDefault(x.outindex);

                if (savedRow != null)
                {
                    savedRow.InjectFrom(x.Result);
                }
            };

            productionServiceClient.GetTblTradeAgreementTransactionCompleted += (d, s) =>
            {
                foreach (var variable in s.Result)
                {
                    var newrow = new TradeAgreementTransaction();
                    newrow.InjectFrom(variable);
                    MainRowList.Add(newrow);
                }
                Loading   = false;
                FullCount = s.fullCount;
                if (SearchWindow != null)
                {
                    SearchWindow.FullCount = s.fullCount;
                    SearchWindow.Loading   = false;
                }
                if (FullCount == 0 && MainRowList.Count == 0)
                {
                    AddNewMainRow(true);
                }
            };

            productionServiceClient.DeleteTblTradeAgreementDetailCompleted += (s, ev) =>
            {
                Loading = false;
                if (ev.Error != null)
                {
                    throw ev.Error;
                }

                var oldrow = SelectedMainRow.DetailsList.FirstOrDefault(x => x.Iserial == ev.Result);

                if (oldrow != null)
                {
                    SelectedMainRow.DetailsList.Remove(oldrow);
                }
            };

            productionServiceClient.SaveTradeAgreementCompleted += (s, sv) =>
            {
                if (SelectedMainRow == null)
                {
                    SelectedMainRow = new TradeAgreementTransaction();
                }
                SelectedMainRow.InjectFrom(sv.savedHeader);
                SelectedMainRow.TblLkpSeason  = sv.savedHeader.TblLkpSeason;
                SelectedMainRow.TblLkpSeason1 = SeasonList.FirstOrDefault(r => r.Iserial == SelectedMainRow.TblLkpSeason);
                //SelectedMainRow.DetailsList.Clear();
                foreach (var item in SelectedMainRow.DetailsList)
                {
                    var newRow = sv.Result.FirstOrDefault(d => d.ItemCode == item.ItemCode && d.TblColor == item.TblColor &&
                                                          d.TblTradeAgreementHeader == item.HeaderIserial && d.AccSize == item.AccSize);
                    if (newRow != null)
                    {
                        item.Iserial       = newRow.Iserial;
                        item.HeaderIserial = newRow.TblTradeAgreementHeader;
                        item.TradeAgreementTransactionIserial = newRow.TblTradeAgreementHeader1.TblTradeAgreementTransaction.Value;
                    }
                }
                RaisePropertyChanged(nameof(IsHeaderSaved));
                MessageBox.Show(strings.Saved);
                Loading = true;
            };
            productionServiceClient.DeleteTradeAgreementHeaderCompleted += (d, s) =>
            {
                SelectedMainRow = new TradeAgreementTransaction();

                if (currentUi.DisplayName == "العربية")
                {
                    MessageBox.Show("Deleted");
                }
                else
                {
                    MessageBox.Show("Deleted");
                }
            };
            // ده هيحتاج تعديل
            LoadingDetail = new RelayCommand <DataGridRowEventArgs>((e) =>
            {
                if (SelectedMainRow.DetailsList.Count < PageSize)
                {
                    return;
                }
                if (SelectedMainRow.DetailsList.Count - 2 < e.Row.GetIndex() && SelectedMainRow.DetailsList.Count < DetailFullCount &&
                    !Loading)
                {
                    string size = null, vendor = null, color = null, ItemType = null, ItemCode = null;
                    string key  = "AccSize";
                    if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                    {
                        size = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                    }
                    key = "Vendor";
                    if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                    {
                        vendor = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                    }

                    key = "Color";
                    if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                    {
                        color = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                    }
                    key = "ItemType";
                    if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                    {
                        ItemType = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                    }
                    key = "ItemCode";
                    if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                    {
                        ItemCode = Convert.ToString(valueObjecttemp.First(w => w.Key.StartsWith(key)).Value);
                    }
                    productionServiceClient.GetTblTradeAgreementDetailListFabricViewAsync(
                        SelectedMainRow.DetailsList.Count, PageSize, SelectedMainRow.Iserial, ItemCode,
                        color, size, vendor, ItemType);
                }
            });
            // ده هيحتاج تعديل
            FilterCommand = new RelayCommand <FilterEvent>((e) =>
            {
                SelectedMainRow.DetailsList.Clear();

                valueObjecttemp.Clear();

                foreach (var f in e.FiltersPredicate)
                {
                    valueObjecttemp.Add(f.FilterColumnInfo.PropertyPath, f.FilterText);
                }

                string size = null, vendor = null, color = null, ItemType = null, ItemCode = null;
                string key  = "AccSize";
                if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                {
                    size = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                }
                key = "Vendor";
                if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                {
                    vendor = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                }

                key = "Color";
                if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                {
                    color = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                }
                key = "ItemType";
                if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                {
                    ItemType = (string)valueObjecttemp.First(w => w.Key.StartsWith(key)).Value;
                }
                key = "ItemCode";
                if (valueObjecttemp.Any(w => w.Key.StartsWith(key)))
                {
                    ItemCode = Convert.ToString(valueObjecttemp.First(w => w.Key.StartsWith(key)).Value);
                }
                productionServiceClient.GetTblTradeAgreementDetailListFabricViewAsync(
                    0, PageSize, SelectedMainRow.Iserial, ItemCode, color, size, vendor, ItemType);
            });
            NewDetail = new RelayCommand <KeyEventArgs>((e) =>
            {
                if (e.Key == Key.Down)
                {
                    //var currentRowIndex = (SelectedMainRow.DetailsList.IndexOf(SelectedDetailRow));
                    //if (currentRowIndex == (SelectedMainRow.DetailsList.Count - 1))
                    //{
                    //    AddNewDetailRow(true);
                    //}
                }
            });
            DeleteDetail = new RelayCommand <KeyEventArgs>((e) =>
            {
                if (e.Key == Key.Delete)
                {
                    var DetailGrid = e.OriginalSource as OsGrid;
                    SelectedDetailRows.Clear();
                    foreach (var row in DetailGrid.SelectedItems)
                    {
                        SelectedDetailRows.Add(row as TradeAgreementDetailModel);
                    }
                    DeleteDetailRow();
                }
            });
            SaveDetail = new RelayCommand <DataGridRowEditEndedEventArgs>((e) => { SaveDetailRow(); });
            Client.GetAllSeasonsCompleted += (s, e) =>
            {
                SeasonList.Clear();
                foreach (var row in e.Result)
                {
                    TblLkpSeason temp = new TblLkpSeason();
                    temp.InjectFrom(row);
                    SeasonList.Add(temp);
                }
            };

            AddNewMainRow(false);
            GetComboData();
            GetMaindata();
        }
Esempio n. 4
0
        public AssetsViewModel()
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                GetItemPermissions(PermissionItemName.AssetsForm.ToString());

                var tblAssetsTypeclient = new CRUD_ManagerServiceClient();
                tblAssetsTypeclient.GetGenericAsync("TblAssetsType", "%%", "%%", "%%", "Iserial", "ASC");

                tblAssetsTypeclient.GetGenericCompleted += (s, sv) =>
                {
                    AssetsTypeList = sv.Result;
                };

                var tblAssetsStatusclient = new CRUD_ManagerServiceClient();
                tblAssetsStatusclient.GetGenericAsync("TblAssetsStatus", "%%", "%%", "%%", "Iserial", "ASC");

                tblAssetsStatusclient.GetGenericCompleted += (s, sv) =>
                {
                    AssetsStatusList = sv.Result;
                };

                var tblProcessorclient = new CRUD_ManagerServiceClient();
                tblProcessorclient.GetGenericAsync("TblProcessor", "%%", "%%", "%%", "Iserial", "ASC");

                tblProcessorclient.GetGenericCompleted += (s, sv) =>
                {
                    ProcessorList = sv.Result;
                };

                var tblHardDiskclient = new CRUD_ManagerServiceClient();
                tblHardDiskclient.GetGenericAsync("TblHardDisk", "%%", "%%", "%%", "Iserial", "ASC");

                tblHardDiskclient.GetGenericCompleted += (s, sv) =>
                {
                    HardDiskList = sv.Result;
                };

                var tblMemoryclient = new CRUD_ManagerServiceClient();
                tblMemoryclient.GetGenericAsync("TblMemory", "%%", "%%", "%%", "Iserial", "ASC");

                tblMemoryclient.GetGenericCompleted += (s, sv) =>
                {
                    MemoryList = sv.Result;
                };

                Client.UpdateOrInsertTblAssetsCompleted += (s, x) => SelectedMainRow.InjectFrom(x.Result);

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

                    SelectedMainRow = new TblAssetsViewModel();
                };
                Client.GetMaxAssetsCompleted += (s, sv) =>
                {
                    SelectedMainRow.Code = sv.Result;
                };
            }
        }
Esempio n. 5
0
        public BankStatementViewModel() : base(PermissionItemName.BankStatement)
        {
            if (!DesignerProperties.IsInDesignTool)
            {
                ApproveBankStat = new RelayCommand(() => {
                    if (SaveCommand.CanExecute(null))
                    {
                        SaveCommand.Execute(null);
                    }
                    SelectedMainRow.Approved    = true;
                    SelectedMainRow.ApproveDate = DateTime.Now;
                    SelectedMainRow.ApprovedBy  = LoggedUserInfo.Iserial;
                    if (SaveCommand.CanExecute(null))
                    {
                        SaveCommand.Execute(null);
                    }
                    if (SelectedMainRow.Approved)//كده نفذ فهعمل جديد
                    {
                        if (NewCommand.CanExecute(null))
                        {
                            NewCommand.Execute(null);
                        }
                    }
                }, () => CheckCanApprove());
                DeleteBankStatDetail = new RelayCommand <object>((o) =>
                {
                    if (((KeyEventArgs)(o)).Key == Key.Delete)
                    {
                        if (SelectedMainRow.Iserial <= 0 || SelectedDetailRow.Iserial <= 0)
                        {
                            SelectedMainRow.TblBankStatDetails.Remove(SelectedDetailRow);
                            if (SelectedMainRow.TblBankStatDetails.Count == 0)
                            {
                                AddNewDetailRow(false);
                            }
                        }
                        else
                        {
                            DeleteDetailRow();
                        }
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                }, (o) => {
                    return(SelectedMainRow != null && !SelectedMainRow.Approved);
                });
                LoadingDetailRows = new RelayCommand <object>((o) =>
                {
                    var e = o as DataGridRowEventArgs;
                    if (SelectedMainRow.TblBankStatDetails.Count < PageSize)
                    {
                        return;
                    }
                    if (SelectedMainRow.TblBankStatDetails.Count - 2 < e.Row.GetIndex() && !Loading)
                    {
                        GetDetailData();
                    }
                });

                NewDetail = new RelayCommand <object>((o) =>
                {
                    var e = o as SelectionChangedEventArgs;
                    if (((KeyEventArgs)(o)).Key == Key.Down)
                    {
                        AddNewDetailRow(false);
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                });
                this.PremCompleted += (s, sv) =>
                {
                    if (this.CustomePermissions.SingleOrDefault(x => x.Code == "BankStatApprove") != null)
                    {
                        CanApprove = true;
                    }
                };
                this.GetCustomePermissions(PermissionItemName.BankStatement.ToString());

                MainRowList = new ObservableCollection <BankStatHeader>();
                AddNewMainRow(false);

                BankStatClient.GetBankStatHeaderCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new BankStatHeader();
                        newrow.InjectFrom(row);
                        MainRowList.Add(newrow);
                    }
                    Loading   = false;
                    FullCount = sv.fullCount;
                    if (SearchWindow != null)
                    {
                        SearchWindow.FullCount = sv.fullCount;
                        SearchWindow.Loading   = false;
                    }
                    if (FullCount == 0 && MainRowList.Count == 0)
                    {
                        AddNewMainRow(false);
                    }
                };
                BankStatClient.GetBankStatDetailCompleted += (s, sv) =>
                {
                    foreach (var row in sv.Result)
                    {
                        var newrow = new BankStatDetail();
                        newrow.InjectFrom(row);
                        //newrow.TblBankTransactionType1 = BankTransactionTypeList.FirstOrDefault(btt => btt.Iserial == newrow.TblBankTransactionType);
                        SelectedMainRow.TblBankStatDetails.Add(newrow);
                    }
                    if (!SelectedMainRow.TblBankStatDetails.Any())
                    {
                        AddNewDetailRow(false);
                    }
                    Loading = false;
                    RaisePropertyChanged(nameof(Total));
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                BankStatClient.UpdateOrInsertBankStatHeaderCompleted += (s, x) =>
                {
                    BankStatHeader savedRow = null;
                    if (x.outindex >= 0)
                    {
                        savedRow = MainRowList.ElementAt(x.outindex);
                    }

                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                        savedRow.TblBank1     = BankList.FirstOrDefault(b => b.Iserial == savedRow.TblBank);
                        savedRow.TblCurrency1 = CurrencyList.FirstOrDefault(c => c.Iserial == savedRow.TblCurrency);
                        savedRow.TblBankStatDetails.Clear();
                        foreach (var item in x.Result.TblBankStatDetails)
                        {
                            var detailTemp = new BankStatDetail();
                            detailTemp.InjectFrom(item);
                            savedRow.TblBankStatDetails.Add(detailTemp);
                        }
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                    DeleteCommand.RaiseCanExecuteChanged();
                    ApproveBankStat.RaiseCanExecuteChanged();
                    DeleteBankStatDetail.RaiseCanExecuteChanged();
                    IsNewChanged();
                };
                BankStatClient.UpdateOrInsertBankStatDetailCompleted += (s, x) =>
                {
                    var savedRow = SelectedMainRow.TblBankStatDetails.ElementAt(x.outindex);
                    if (savedRow != null)
                    {
                        savedRow.InjectFrom(x.Result);
                        savedRow.TblBankTransactionType1 = BankTransactionTypeList.FirstOrDefault(bt => bt.Iserial == savedRow.TblBankTransactionType);
                    }
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };
                BankStatClient.DeleteBankStatHeaderCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }

                    var oldrow = MainRowList.FirstOrDefault(x => x.Iserial == ev.Result);
                    if (oldrow != null)
                    {
                        MainRowList.Remove(oldrow);
                    }
                };
                BankStatClient.DeleteBankStatDetailCompleted += (s, ev) =>
                {
                    if (ev.Error != null)
                    {
                        throw ev.Error;
                    }
                    var oldrow = SelectedMainRow.TblBankStatDetails.FirstOrDefault(x => x.Iserial == ev.Result.Iserial);
                    if (oldrow != null)
                    {
                        SelectedMainRow.TblBankStatDetails.Remove(oldrow);
                    }
                    RaisePropertyChanged(nameof(Total));
                    RaisePropertyChanged(nameof(IsHeaderHasDetails));
                };

                BankStatClient.IsBankStatHeaderHasMatchedRowsCompleted += (s, e) =>
                {
                    if (SelectedMainRow.Iserial == e.Iserial)
                    {
                        hasMatched = e.Result;
                    }
                    else
                    {
                        hasMatched = false;
                    }
                    RaisePropertyChanged(nameof(IsReadOnly));
                };

                BankStatClient.GetLookUpBankTransactionTypeCompleted += (s, e) =>
                {
                    BankTransactionTypeList = e.Result;
                };
                BankStatClient.GetLookUpBankCompleted += (s, e) =>
                {
                    BankList = e.Result;
                };
                BankStatClient.GetLookUpCurrencyCompleted += (s, e) =>
                {
                    CurrencyList = e.Result;
                };

                BankStatClient.InsertImportedItemsCompleted += (s, e) =>
                {
                    for (int i = 0; i < RemainningImportList.Count; i = i + step)
                    {
                        bool approve = (i + step >= RemainningImportList.Count);                                       //هل دى اخر لفة
                        var  temp    = new ObservableCollection <ImportedBankStatement>(RemainningImportList.Skip(i).Take(step));
                        BankStatClient.InsertRemainingImportedItemsAsync(e.Result, temp, LoggedUserInfo.DatabasEname); // First Time
                        requestes++;
                    }
                    ImportHeaderIserial = e.Result;
                    Loading             = false;
                };
                BankStatClient.InsertRemainingImportedItemsCompleted += (s, e) =>
                {
                    requestes--;// على اساس ان الريكويست اسرع من الريسبونس

                    foreach (var item in e.Result)
                    {
                        error += item + "\r\n";
                    }
                    if (e.Error != null)
                    {
                        requestes = -1;
                        throw e.Error;
                    }
                    else if (requestes == 0)// كده ده اخر واحد
                    {
                        if (string.IsNullOrWhiteSpace(error))
                        {
                            MessageBox.Show("Import Completed Succesfully");
                            //هجيب الريكورد الى اتحفظ ده اعرضه بقى
                            BankStatClient.GetBankStatHeaderByIserialAsync(ImportHeaderIserial, LoggedUserInfo.DatabasEname);
                            ImportHeaderIserial = -1;
                            return;
                        }
                        BankStatClient.DeleteBankStatByIserialAsync(ImportHeaderIserial, LoggedUserInfo.DatabasEname);
                        ImportHeaderIserial = -1;
                        if (MessageBox.Show("Import Completed, Do you want to view logs?", "Info", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                        {
                            new LogView(error).Show();
                            error = "";
                        }
                    }
                };
                BankStatClient.GetBankStatHeaderByIserialCompleted += (s, e) =>
                {
                    SelectedMainRow.InjectFrom(e.Result);
                    SelectedMainRow.TblBank1     = BankList.FirstOrDefault(b => b.Iserial == SelectedMainRow.TblBank);
                    SelectedMainRow.TblCurrency1 = CurrencyList.FirstOrDefault(c => c.Iserial == SelectedMainRow.TblCurrency);
                    if (SelectedMainRow.TblBankStatDetails != null)
                    {
                        SelectedMainRow.TblBankStatDetails = new ObservableCollection <BankStatDetail>();
                    }
                    RaisePropertyChanged(nameof(SelectedMainRow));
                    DeleteCommand.RaiseCanExecuteChanged();
                    ApproveBankStat.RaiseCanExecuteChanged();
                    DeleteBankStatDetail.RaiseCanExecuteChanged();
                    IsNewChanged();
                    GetDetailData();
                };
                BankStatClient.InsertExcelFileDateCompleted += (s, e) => {
                    //if (e.Error != null) MessageBox.Show(e.Error.Message);
                };
                ImportFromExcelCommand = new RelayCommand(() => {
                    if (!ValidHeaderData())
                    {
                        return;
                    }
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Filter         = "Excel Files (*.xls)|*.xls";
                    if (ofd.ShowDialog() == true)
                    {
                        var importedList = new ObservableCollection <ImportedBankStatement>();
                        var fs           = ofd.File.OpenRead();

                        var book  = Workbook.Open(fs);
                        var sheet = book.Worksheets[0];

                        var dataList = new ObservableCollection <Models.Excel.CellModel>();
                        for (int i = sheet.Cells.FirstColIndex; i < sheet.Cells.LastColIndex + 1; i++)
                        {
                            for (int j = sheet.Cells.FirstRowIndex; j < sheet.Cells.LastRowIndex + 1; j++)
                            {
                                var cellModel = new Models.Excel.CellModel()
                                {
                                    Column = i,
                                    Row    = j,
                                    Value  = sheet.Cells[j, i].StringValue.ToUpper(),
                                };
                                dataList.Add(cellModel);
                                if (i == 1)
                                {
                                    var t = sheet.Cells[j, i].StringValue.ToUpper().Split('-');
                                    if (t.Length == 3)
                                    {
                                        cellModel.Day    = t[0];
                                        cellModel.Mounth = t[1];
                                        cellModel.Year   = t[2];
                                    }
                                }
                            }
                        }
                        TblBankStatHeader headerRow = new TblBankStatHeader();
                        headerRow.InjectFrom(SelectedMainRow);
                        BankStatClient.InsertExcelFileDateAsync(headerRow, dataList, LoggedUserInfo.DatabasEname);// new ObservableCollection<Models.Excel.CellModel>(dataList.Take(300)));
                        //int docDateIndex = 0, transactionTypeIndex = 0, descriptionIndex = 0, amountIndex = 0, chequeNoIndex = 0, depositNoIndex = 0;
                        //FillList(importedList, sheet, ref docDateIndex, ref transactionTypeIndex, ref descriptionIndex, ref amountIndex, ref chequeNoIndex, ref depositNoIndex);
                        //InsertImportedDetail(importedList);
                    }
                });
                MatchCommand = new RelayCommand(() => {
                    if (SelectedMainRow.Iserial <= 0)
                    {
                        MessageBox.Show("Bank Statement must save first");
                        return;
                    }
                    var matchingView            = new BankStatementMatchView();
                    var matchingViewModel       = new BankStatementMatchViewModel();
                    matchingViewModel.HeaderRow = SelectedMainRow;
                    matchingView.DataContext    = matchingViewModel;
                    matchingView.Show();
                });

                GetComboData();
                GetMaindata();
            }
        }