static void Main(string[] args)
        {
            var name     = "Bob";
            var age      = 21;
            var isRabbit = true;

            {
                int dupaukryta = 12;
                WriteLine(dupaukryta);
            }

            Type nameType     = name.GetType();
            Type ageType      = age.GetType();
            Type isRabbitType = isRabbit.GetType();

            WriteLine($"name is type {nameType}");
            WriteLine($"name is type {name.GetType()}");
            WriteLine($"age is type {ageType}");
            WriteLine($"isRabbit is type {isRabbitType}");

            int a = 23;

            string s = a.ToString();

            WriteLine($"{s} = {a}");

            char characters     = '\x0051';
            char characters1    = (char)65;
            char alert          = '\a';
            char backspace      = '\b';
            char formFeed       = '\f';
            char Carriagereturn = '\r';
            char vericaltab     = '\v';

            WriteLine(characters + " " + characters1);
            //WriteLine(alert);
            WriteLine("stackoverflow " + '\b' + " is " + backspace + " good");
            WriteLine(vericaltab);
            WriteLine("dupa" + Carriagereturn + "pa");
            //WriteLine("stackoverflow" + formFeed + "is" + formFeed + "good");


            string jeby = @"'Cos tam mam
            ale nie dam";

            WriteLine(jeby);

            int b = 2;


            if (DoSomething(b) != 0)
            {
                WriteLine(DoSomething(b));
            }
            else
            {
                WriteLine("Zero");
            }
            WriteLine("\n\n\n\n");

            string[] arrayOfStrings = new string[5];

            for (int i = 0; i < 5; i++)
            {
                arrayOfStrings[i] = "string_" + i.ToString();
            }

            int[] arrayOfInts = new int[5];

            goto Label1;
            foreach (var item in arrayOfStrings)
            {
                WriteLine(item);
            }
            arrayOfInts[2] = 2;
Label1:
            foreach (var item in arrayOfInts)
            {
                Write($"{item} \t");
            }
            WriteLine();

            TimeOfDay time = TimeOfDay.Afternoon;

            WriteLine(time.ToString());

            TimeOfDay time2 = (TimeOfDay)Enum.Parse(typeof(TimeOfDay), "morning", true);

            WriteLine((int)time2);

            //namespace
            Introduction::NamespaceExample NSEx = new Introduction::NamespaceExample();

            WriteLine(NSEx.GetNamespace());


            for (int i = 0; i < args.Length; i++)
            {
                WriteLine(args[i]);
            }
            var customer1 = new PhoneCustomer();


            WriteLine($"\n{customer1.GetType()}");
            WriteLine($"{customer1.Data.GetType()}");
            WriteLine($"{customer1.DataAutoImplemented}");

            string message      = "WITAM";
            string upperMessage = message.ToLower();

            WriteLine(upperMessage);

            int xMessage = 2017;

            message += xMessage.ToString();
            WriteLine(message);


            // C# 6.0 pl

            int[,] matrix2D = new int[3, 3];

            int[,] rectangularMatrix =
            {
                { 0, 1, 2 },
                { 0, 2, 3 },
                { 1, 2, 3 }
            };

            int[][] matrix = new int[][]
            {
                new int[] { 3, 3, 3 },
                new int[] { 2, 2, 2 },
                new int[] { 1, 1, 1, 2 }
            };

            var matrixVar = new int[][]
            {
                new int[] { 3, 3, 3 },
                new int[] { 2, 2, 2 },
                new int[] { 1, 1, 1, 2 }
            };

            var charArray = new[] { 'a', 'b', 'c' };

            //różna długość tablicy wewn
            int[][] matrix2 = new int[3][];
        }
Beispiel #2
0
        public SellViewModel()
        {
            loadUserCurrentLogin();
            TotalPrice   = 0;
            IsEnableName = false;
            List         = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable);
            ListSupplier = new List <SupplierTable>(DataProvider.Ins.Entities.SupplierTable);
            ListUnit     = new List <UnitTable>(DataProvider.Ins.Entities.UnitTable);
            ListBill     = new List <BillModel>();
            _ListTemp    = new List <BillModel>();

            LoadEditCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { LoadDialogAccountEdit(); });

            AddBillCommand = new RelayCommand <object>((p) =>
            {
                if (SelectedItems == null)
                {
                    return(false);
                }
                SelectedItemsBill = null;
                return(true);
            },
                                                       (p) =>
            {
                BillModel bill            = new BillModel();
                ProductTable billProduct  = new ProductTable();
                billProduct.ID            = SelectedItems.ID;
                billProduct.DisplayName   = SelectedItems.DisplayName;
                billProduct.SupplierTable = SelectedItems.SupplierTable;
                billProduct.UnitTable     = SelectedItems.UnitTable;
                int Price     = 0;
                var listPrice = DataProvider.Ins.Entities.ProductTable.Where(x => x.ID == SelectedItems.ID).Select(x => x.Price);

                foreach (var item in listPrice)
                {
                    Price = item;
                }

                bill.product      = billProduct;
                bill.Price        = Price;
                bill.Amount       = 1;
                bill.PriceItems   = Price;
                bill.AmountChange = AmountChange;

                if (LoadInventory(bill.product.ID) <= 0)
                {
                    LoadDialogError("Sản Phẩm Không Còn Trong Kho! Vui Lòng Liên Hệ Quản Trị Viên!");
                    return;
                }

                TotalPrice += Price;

                var listCheckDuplicate = _ListTemp.Where(x => x.product.ID == bill.product.ID);
                if (listCheckDuplicate.Count() != 0)
                {
                    int DuplicateProduct = _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount;
                    _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount      = DuplicateProduct + 1;
                    _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().PriceItems += Price;
                    ListBill      = new List <BillModel>(_ListTemp);
                    SelectedItems = null;
                    return;
                }
                _ListTemp.Add(bill);
                ListBill      = new List <BillModel>(_ListTemp);
                SelectedItems = null;
            });

            DeleteItemInBill = new RelayCommand <object>((p) =>
            {
                if (SelectedItemsBill == null)
                {
                    return(false);
                }
                SelectedItems = null;
                return(true);
            },
                                                         (p) =>
            {
                var FindToDelete = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault();
                TotalPrice      -= FindToDelete.PriceItems;
                _ListTemp.Remove(FindToDelete);
                ListBill          = new List <BillModel>(_ListTemp);
                SelectedItemsBill = null;
            });

            AmountChange = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                     (p) =>
            {
                try
                {
                    var FindToEdit        = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault();
                    TotalPrice           -= FindToEdit.PriceItems;
                    FindToEdit.Amount     = SelectedItemsBill.Amount;
                    FindToEdit.PriceItems = FindToEdit.Amount * FindToEdit.Price;
                    TotalPrice           += FindToEdit.PriceItems;
                    ListBill = new List <BillModel>(_ListTemp);
                }
                catch
                {
                    MessageBox.Show(Message);
                }
            });

            PhoneCustomerChange = new RelayCommand <object>((p) =>
            {
                if (PhoneCustomer.ToString().Length < 9)
                {
                    return(false);
                }
                return(true);
            },
                                                            (p) =>
            {
                var Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault();
                if (Customer != null)
                {
                    NameCustomer = Customer.FullName;
                    IsEnableName = false;
                    return;
                }
                NameCustomer = "";
                IsEnableName = true;
            });

            CreateBill = new RelayCommand <object>((p) =>
            {
                if (TotalPrice <= 0 || NameCustomer == null || PhoneCustomer.ToString().Length < 9)
                {
                    return(false);
                }
                return(true);
            },
                                                   (p) =>
            {
                foreach (var item in _ListTemp)
                {
                    if (LoadInventory(item.product.ID) - item.Amount < 0)
                    {
                        LoadDialogError("Số Lượng Sản Phẩm Không Đủ Đáp Ứng Nhu Cầu!");
                        return;
                    }
                }

                if (IsEnableName)
                {
                    CustomerTable customer = new CustomerTable();
                    customer.FullName      = NameCustomer;
                    customer.Phone         = "0" + PhoneCustomer.ToString();
                    customer.Address       = "";
                    DataProvider.Ins.Entities.CustomerTable.Add(customer);
                    DataProvider.Ins.Entities.SaveChanges();
                }
                var ID_Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault();

                OutputTable output = new OutputTable();
                output.ID_User     = (int)App.Current.Properties["UserID"];
                output.DateOutput  = DateTime.Now;
                output.ID_Customer = ID_Customer.ID;
                DataProvider.Ins.Entities.OutputTable.Add(output);
                DataProvider.Ins.Entities.SaveChanges();
                var ID_Output = DataProvider.Ins.Entities.OutputTable.Where(x => x.ID_User == output.ID_User &&
                                                                            x.ID_Customer == output.ID_Customer && x.DateOutput == output.DateOutput.Date).FirstOrDefault();

                int ID = ID_Output.ID;
                OutPutDetailTable outPutDetail = new OutPutDetailTable();
                foreach (var item in _ListTemp)
                {
                    outPutDetail.Count      = item.Amount;
                    outPutDetail.ID_Product = item.product.ID;
                    outPutDetail.ID_Output  = ID;
                    outPutDetail.Price      = item.Price;
                    outPutDetail.TotalPrice = item.PriceItems;
                    DataProvider.Ins.Entities.OutPutDetailTable.Add(outPutDetail);
                    DataProvider.Ins.Entities.SaveChanges();
                }
                LoadDialogSuccessSale();
                TotalPrice    = 0;
                _ListBill     = null;
                ListBill      = null;
                NameCustomer  = null;
                PhoneCustomer = 0;
                IsEnableName  = false;
            });

            DestroyCommand = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                       (p) =>
            {
                TotalPrice    = 0;
                ListBill      = null;
                _ListBill     = null;
                NameCustomer  = null;
                PhoneCustomer = 0;
                IsEnableName  = false;
                LoadDialogDeleted();
            });

            SearchCommand = new RelayCommand <object>((p) =>
            {
                return(true);
            },
                                                      (p) =>
            {
                if (SearchTerm == null)
                {
                    return;
                }

                List = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable.Where(
                                                   x => x.DisplayName.ToLower().Contains(SearchTerm) ||
                                                   x.SupplierTable.DisplayName.ToLower().Contains(SearchTerm) || x.UnitTable.Descriptions.ToLower().Contains(SearchTerm)));
            });

            OpenBillWindow = new RelayCommand <Window>((p) =>
            {
                return(true);
            },
                                                       (p) =>
            {
                p.Close();
                BillWindow wd = new BillWindow();
                wd.ShowDialog();
            });
        }