Exemple #1
0
        /*
         * Get All Receipts for this customer if season is null
         * Get All Receipts for this customer in a certain season if season is not null different from 0  and -1
         * Get All Receipts for this customer that don't have a season if season is 0
         * Get All Receipts for this customer that have a season if season is -1
         */
        public BindableCollection <ReceiptModel> GetMyReceipts(int?currency = null, int?season = null)
        {
            BindableCollection <ReceiptModel> receipts = new BindableCollection <ReceiptModel>();

            if (this.Id == 0)
            {
                return(null);
            }
            else
            {
                ReceiptModel receipt = new ReceiptModel();
                string[]     value   = new string[2] {
                    "number", Id.ToString()
                };
                List <KeyValuePair <string, string[]> > Data = new List <KeyValuePair <string, string[]> >
                {
                    new KeyValuePair <string, string[]>("customer_id", value)
                };
                switch (season)
                {
                case null:
                    break;

                case -1:
                    value = new string[2] {
                        "number", "NOT-NULL"
                    };
                    break;

                case 0:
                    value = new string[2] {
                        "number", "NULL"
                    };
                    break;

                default:
                    value = new string[2] {
                        "number", season.ToString()
                    };
                    break;
                }
                if (season != null)
                {
                    Data.Add(new KeyValuePair <string, string[]>("season_id", value));
                }
                receipts = receipt.GiveCollection(receipt.FindByParameters(Data));
            }
            if (currency != null)
            {
                foreach (ReceiptModel receipt in receipts)
                {
                    receipt.SetFullAmount((int)currency);
                }
            }
            return(receipts);
        }
        public BindableCollection <ReceiptModel> GiveCollection(DataTable cs)
        {
            List <ReceiptModel> output = new List <ReceiptModel>();
            SeasonModel         sm     = new SeasonModel();
            CustomerModel       cm     = new CustomerModel();
            CurrencyModel       cr     = new CurrencyModel();
            FactureModel        fm     = new FactureModel();

            foreach (DataRow row in cs.Rows)
            {
                cm = cm.Get(System.Convert.ToInt32(row[2].ToString()));
                ReceiptModel ctm = new ReceiptModel
                {
                    Id           = System.Convert.ToInt32(row[0].ToString()),
                    Number       = System.Convert.ToInt32(row[1].ToString()),
                    Customer     = cm.Id,
                    CustomerName = cm.Name,
                };
                if (row[3].ToString() != null && row[3].ToString() != string.Empty)
                {
                    sm             = sm.Get(System.Convert.ToInt32(row[3].ToString()));
                    ctm.Season     = sm.Id;
                    ctm.SeasonYear = sm.Year;
                }
                if (row[4].ToString() != null && row[4].ToString() != string.Empty)
                {
                    ctm.Details = row[4].ToString();
                }
                if (row[5].ToString() != null && row[5].ToString() != string.Empty)
                {
                    ctm.Amount = System.Convert.ToDecimal(row[5].ToString());
                    if (row[6].ToString() != null && row[6].ToString() != string.Empty)
                    {
                        cr                 = cr.Get(System.Convert.ToInt32(row[6].ToString()));
                        ctm.Currency       = cr.Id;
                        ctm.CurrencySymbol = cr.Symbol;
                    }
                }
                if (row[7].ToString() != null && row[7].ToString() != string.Empty)
                {
                    ctm.Delivery = System.Convert.ToDateTime(row[7].ToString());
                }
                if (row[8].ToString() != null && row[8].ToString() != string.Empty)
                {
                    fm          = fm.Get(System.Convert.ToInt32(row[8].ToString()));
                    ctm.Facture = fm.Id;
                }
                if (row[9].ToString() != null && row[9].ToString() != string.Empty)
                {
                    ctm.Cheque = row[9].ToString();
                }
                output.Add(ctm);
            }
            return(new BindableCollection <ReceiptModel>(output));
        }
 public int?GetReceipt()
 {
     if (Id.ToString() != "0")
     {
         ReceiptModel receipt = new ReceiptModel();
         receipt = receipt.GetMeByFacture(Id);
         if (receipt != null)
         {
             return(receipt.Id);
         }
     }
     return(null);
 }