Beispiel #1
0
 private void FillCombos()
 {
     if (Facture.Season.ToString() != null)
     {
         Season = new SeasonModel();
         Season = Season.Get(Facture.Season);
         for (int i = 0; i < Seasons.Count(); i++)
         {
             if (Season.Id == Seasons[i].Id)
             {
                 SelectedSeason = i;
                 break;
             }
         }
     }
     else
     {
         SelectedSeason = null;
     }
     Customer = new CustomerModel();
     Customer = Customer.Get(Facture.Customer);
     for (int i = 0; i < Customers.Count(); i++)
     {
         if (Customer.Id == Customers[i].Id)
         {
             SelectedCustomer = i;
             break;
         }
     }
 }
Beispiel #2
0
        private void FillSelected(ProductModel product)
        {
            CustomerModel c  = new CustomerModel();
            DataTable     dt = Customer.All();

            c = c.Get(System.Convert.ToInt32(product.Customer));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string RowID      = dt.Rows[i][0].ToString();
                string CustomerId = Customer.Id.ToString();
                if (RowID == CustomerId)
                {
                    SelectedCustomer = i;
                    break;
                }
            }
            if (Price != 0 && Price != null)
            {
                CurrencyModel cm  = new CurrencyModel();
                DataTable     cts = cm.All();
                cm = cm.Get(System.Convert.ToInt32(product.Currency));
                for (int i = 0; i < cts.Rows.Count; i++)
                {
                    string RowID      = cts.Rows[i][0].ToString();
                    string CurrencyId = Currency.Id.ToString();
                    if (RowID == CurrencyId)
                    {
                        SelectedCurrency = i;
                        break;
                    }
                }
            }
        }
 public void FillForm(DataTable customers, DataTable seasons, DataTable currencies)
 {
     Delivery = (DateTime)Receipt.Delivery;
     Number   = (int)Receipt.Number;
     Details  = Receipt.Details;
     Cheque   = Receipt.Cheque;
     for (int i = 0; i < customers.Rows.Count; i++)
     {
         string id    = Receipt.Customer.ToString();
         string RowId = customers.Rows[i][0].ToString();
         if (id == RowId)
         {
             SelectedCustomer = i;
             Customer         = Customers[i];
             break;
         }
     }
     if (Receipt.Season != null)
     {
         for (int i = 0; i < seasons.Rows.Count; i++)
         {
             if (Receipt.Season.ToString() == seasons.Rows[i][0].ToString())
             {
                 SelectedSeason = i;
                 Season         = Seasons[i];
                 break;
             }
         }
     }
     if (Receipt.Currency != null)
     {
         for (int i = 0; i < currencies.Rows.Count; i++)
         {
             if (Receipt.Currency.ToString() == currencies.Rows[i][0].ToString())
             {
                 SelectedCurrency = i;
                 Currency         = Currencies[i];
                 break;
             }
         }
     }
     if (Receipt.Facture != null)
     {
         CustomerModel cm = new CustomerModel();
         cm         = cm.Get((int)Receipt.Customer);
         Factures   = cm.GetMyUnClearedFacturesWithOldCleared((int)Receipt.Facture);
         OldFacture = Receipt.Facture;
         for (int i = 0; i < Factures.Count; i++)
         {
             if (Receipt.Facture.ToString() == Factures[i].Id.ToString())
             {
                 SelectedFacture = i;
                 Facture         = Factures[i];
                 break;
             }
         }
     }
     Amount = (float)Receipt.Amount;
 }
Beispiel #4
0
        public EditProductViewModel(ProductModel product, bool contsant_customer = false)
        {
            // Get Currencies
            CurrencyModel currency = new CurrencyModel();

            Currencies = currency.GiveCollection(currency.All());
            // Get Customers
            CustomerModel customers      = new CustomerModel();
            DataTable     CustomersTable = customers.All();

            Customers = customers.GiveCollection(CustomersTable);
            // Fill Data
            Product         = product;
            Product.Changed = new List <string>();
            Id       = product.Id;
            Name     = product.Name;
            Customer = customers.Get((int)Product.Customer);
            Details  = product.Details;
            if (product.Price != null && Product.Currency != null)
            {
                Price    = product.Price;
                Currency = currency.Get((int)Product.Currency);
            }
            // Get Images
            Image           = Product.GetImageFromDb();
            Product.Changed = new List <string>();
            FillSelected(product);
            if (contsant_customer)
            {
                IsCustomerEnabled = false;
            }
            else
            {
                IsCustomerEnabled = true;
            }
        }
        public void Search()
        {
            if (SearchText != null && SearchText.Trim() != "")
            {
                try
                {
                    CustomerModel customer = new CustomerModel();
                    switch (SearchType)
                    {
                    case "Id":
                        customer = customer.Get(System.Convert.ToInt32(SearchText));
                        if (customer == null || customer.Name == null)
                        {
                            throw new Exception("Can't find Customer with Id " + SearchText);
                        }
                        BtnView(customer);
                        break;

                    case "Name":
                        customer  = new CustomerModel();
                        Customers = customer.SearchBy("Name", SearchText);
                        if (Customers.Count == 0)
                        {
                            throw new Exception("There is no name like " + SearchText);
                        }
                        if (Customers.Count == 1)
                        {
                            BtnView(Customers[0]);
                        }
                        if (Customers.Count > 1)
                        {
                            ActivateItem(new BlankViewModel());
                        }
                        break;

                    case "Customer Type Name":
                        customer  = new CustomerModel();
                        Customers = customer.SearchBy("Customer Type Name", SearchText);
                        if (Customers.Count == 0)
                        {
                            throw new Exception("There is no customer type like " + SearchText);
                        }
                        if (Customers.Count == 1)
                        {
                            BtnView(Customers[0]);
                        }
                        if (Customers.Count > 1)
                        {
                            ActivateItem(new BlankViewModel());
                        }
                        break;

                    case "Customer Type Id":
                        customer  = new CustomerModel();
                        Customers = customer.SearchBy("Customer Type Id", SearchText);
                        if (Customers.Count == 0)
                        {
                            throw new Exception("There is no customers of type Id " + SearchText);
                        }
                        if (Customers.Count == 1)
                        {
                            BtnView(Customers[0]);
                        }
                        if (Customers.Count > 1)
                        {
                            ActivateItem(new BlankViewModel());
                        }
                        break;

                    default:
                        MessageBox.Show("Set a search type please!", "Search Type", MessageBoxButton.OK, MessageBoxImage.Information);
                        break;
                    }
                }
                catch (Exception e)
                {
                    ActivateItem(new BlankViewModel());
                    MessageBox.Show(e.Message, "Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }