Esempio n. 1
0
        public SearchForStore(UserJobsViewModel viewModel)
        {
            InitializeComponent();
            DataContext = viewModel;

            _client.SeasonForStoreByUserCompleted += (s, sv) =>
            {
                viewModel.StoreList.Clear();
                var iserials = new List <int>();
                if (viewModel.SelectedMainRow.AllowedStores != null)
                {
                    iserials = viewModel.SelectedMainRow.AllowedStores.Split('|').Select(int.Parse).ToList();
                }
                foreach (var tblStore in sv.Result)
                {
                    var newrow = new TblStoreViewModel();
                    newrow.InjectFrom(tblStore);
                    //newrow.Saved = iserials.Contains(tblStore.iserial);
                    viewModel.StoreList.Add(newrow);
                }
            };
            string code = viewModel.SelectedMainRow.CompanyPerRow.Code;

            if (viewModel.SelectedMainRow.TblCompanySecondary != null)
            {
                code =
                    viewModel.CompanyList.FirstOrDefault(x => x.Iserial == viewModel.SelectedMainRow.TblCompanySecondary)
                    .Code;
            }

            if (code == "HQ")
            {
                code = "Ccnew";
            }

            _client.SeasonForStoreByUserAsync(null, null, code);
        }
Esempio n. 2
0
        public PromoHeaderGifts()
        {
            GetItemPermissions(PermissionItemName.PromotionForm.ToString());
            GetCustomePermissions(PermissionItemName.PromotionForm.ToString());
            SelectedDetailRows = new ObservableCollection <TblPromoDetailViewModel>();
            TransactionHeader  = new TblPromoHeaderGifts();
            SelectedMainRow    = new TblPromoHeaderGifts();
            MainRowList        = new SortableCollectionView <TblPromoHeaderGifts>();
            TypesListDoc       = new SortableCollectionView <TypesDocViewModel>();
            RangeList          = new SortableCollectionView <RangeViewModel>();
            DetailList         = new SortableCollectionView <TBLEVENTUALHEADER>();
            StoreList          = new SortableCollectionView <TblStore>();
            Stores             = new ObservableCollection <TblStoreViewModel>();
            TypesListDoc.Add(new TypesDocViewModel()
            {
                No   = 0,
                Name = "Gifts"
            });

            Client.SearchforsStoreNameCompleted += (M, K) =>
            {
                Loading   = false;
                StoreList = K.Result;

                //OnSupplierCompleted();
            };

            Client.GetPrmotionRangeCompleted += (s, sv) =>
            {
                if (sv.Result != null)
                {
                    MessageBox.Show("This Range Is Already Exist");
                }
                else
                {
                    var FromCodeInt = Convert.ToInt32(TransactionHeader.FromCode);
                    var Difference  = Convert.ToInt32(TransactionHeader.ToCode) - Convert.ToInt32(TransactionHeader.FromCode);
                    var random      = new Random();
                    for (var x = 0; x < Difference; x++)
                    {
                        var codeNo       = FromCodeInt + x;
                        var randomNumber = random.Next(0, 9999);
                        TransactionHeader.DetailsList.Add(new TblPromoDetailViewModel()
                        {
                            Code         = codeNo.ToString(),
                            PIN          = randomNumber.ToString(),
                            SelecteIndex = x + 1
                        }
                                                          );
                    }
                }

                for (var i = 0; i < TransactionHeader.DetailsList.Count; i++)
                {
                    var codeNo = +i;
                }
            };
            Client.DeleteTblPromoDetailCompleted += (s, ev) =>
            {
                if (ev.Error != null)
                {
                    throw ev.Error;
                }

                var oldrow = MainRowList.FirstOrDefault(x => x.GlSerial == ev.Result);
                if (oldrow != null)
                {
                    MainRowList.Remove(oldrow);
                }
            };
            Client.UpdateAndInsertTblPromoDetailCompleted += (x, y) =>
            {
                var savedRow = (TblPromoDetailViewModel)TransactionHeader.DetailsList.GetItemAt(y.outindex);

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

            Client.GetStoresCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    var newrow = new TblStoreViewModel();
                    newrow.InjectFrom(row);

                    Stores.Add(newrow);
                }

                DetailFullCount = sv.fullCount;
                Loading         = false;
            };
            Client.GetDetailCompleted += (s, sv) =>
            {
                foreach (var row in sv.Result)
                {
                    var newrow = new TblPromoDetailViewModel();
                    newrow.InjectFrom(row);
                    TransactionHeader.DetailsList.Add(newrow);
                    newrow.SelecteIndex = TransactionHeader.DetailsList.IndexOf(newrow) + 1;
                }

                if (ExcelSheetprop == true)
                {
                    SaveFileDialog sDialog = new SaveFileDialog();
                    sDialog.Filter = "Excel Files(*.xls)|*.xls";
                    if (sDialog.ShowDialog() == true)
                    {
                        // create an instance of excel workbook
                        Workbook workbook = new Workbook();
                        // create a worksheet object
                        Worksheet worksheet = new Worksheet("Friends");
                        // write data in worksheet cells
                        for (int i = 0; TransactionHeader.DetailsList.Count() > i; i++)
                        {
                            worksheet.Cells[i, 2] = new Cell(TransactionHeader.Msg + "  Expiry:" + TransactionHeader.TODate.ToString() + "   Code:" + TransactionHeader.DetailsList.ElementAt(i).Code + "  Pin:" + TransactionHeader.DetailsList.ElementAt(i).PIN);
                        }
                        for (int i = 0; TransactionHeader.DetailsList.Count() > i; i++)
                        {
                            worksheet.Cells[1 + i, 0] = new Cell("MobileNo");
                            worksheet.Cells[1 + i, 1] = new Cell(TransactionHeader.DetailsList.ElementAt(i).MobileNo);
                        }

                        workbook.Worksheets.Add(worksheet);
                        Stream sFile = sDialog.OpenFile();

                        // save method needs a stream object to write an excel file.
                        workbook.Save(sFile);
                    }
                }
                Loading        = false;
                ExcelSheetprop = false;
            };

            Client.GetevDataCompleted += (s, sv) =>
            {
                DetailList.Clear();
                foreach (var row in sv.Result)
                {
                    DetailList.Add(row);
                }
                DetailFullCount = sv.fullCount;
                Loading         = false;
            };

            Client.SearchTblPromoHeaderAllCompleted += (y, v) =>
            {
                foreach (var row in v.Result)
                {
                    Loading = false;

                    // غيرت حاجة هنا ممكن تكون غلط
                    var newrow = new TblPromoHeaderGifts();
                    newrow.InjectFrom(row);
                    newrow.StorePerRow = row.TblStore1;
                    MainRowList.Add(newrow);
                }
            };

            Client.UpdateOrInsertTblPromoHeaderCompleted += (s, x) =>
            {
                if (x.Error == null)
                {
                    TransactionHeader.InjectFrom(x.Result);
                    SaveMainRowExc();
                    MessageBox.Show("Saved Successfully");
                }
                else
                {
                    MessageBox.Show(x.Error.Message);
                }
                Loading = false;

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