Exemplo n.º 1
0
 public ChequeManageForm()
 {
     this.db = new StoreDBEntities();
     this.InitializeComponent();
     this.abrDateEnd.SelectedDate = (System.DateTime.Now);
     this.abrDateStart.SelectedDate = (System.DateTime.Now);
 }
Exemplo n.º 2
0
 public DocumentsManageForm()
 {
     this.edit = false;
     this.db = new StoreDBEntities();
     this.selected = 0;
     this.InitializeComponent();
 }
Exemplo n.º 3
0
 public ItemMergeForm()
 {
     InitializeComponent();
     threadRight = new Thread(new ThreadStart(FindRight));
     threadLeft = new Thread(new ThreadStart(FindLeft));
     db = new StoreDBEntities();
 }
Exemplo n.º 4
0
 public ItemManageForm()
 {
     this.InitializeComponent();
     DB = new StoreDBEntities();
     Control.CheckForIllegalCrossThreadCalls = false;
     this.T = new System.Threading.Thread(new System.Threading.ThreadStart(this.FixCounts));
 }
Exemplo n.º 5
0
 public ReturnItemForm()
 {
     this.db = new StoreDBEntities();
     Control.CheckForIllegalCrossThreadCalls = false;
     this.T = new System.Threading.Thread(new System.Threading.ThreadStart(this.UpdateList));
     this.T.Start();
     this.InitializeComponent();
 }
Exemplo n.º 6
0
 public ItemSearchForm()
 {
     this.InitializeComponent();
     this.db = new StoreDBEntities();
     this.T = new System.Threading.Thread(new System.Threading.ThreadStart(this.FillTable));
     this.TR = new System.Threading.Thread(new System.Threading.ThreadStart(this.compileReport));
     Control.CheckForIllegalCrossThreadCalls = false;
     this.queryChanged = false;
     this.T.Start();
 }
Exemplo n.º 7
0
 public static void SaveCashPayDocument(Invoice Inv)
 {
     var db = new StoreDBEntities();
     long accountid = 0;
     try
     {
         accountid = db.Accounts.AsEnumerable().First(x => x.DistributorID == Inv.TarafID).Id;
     }
     catch (InvalidOperationException)
     {
         Account newAcc = new Account
         {
             Name = Inv.Distributor.Name,
             Description = " ",
             CustomerID = 0,
             DistributorID = Inv.TarafID,
             BankAccountID = 0
         };
         db.Accounts.AddObject(newAcc);
         db.SaveChanges();
         accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id;
         //db.AcceptAllChanges();
         //db = new StoreDBEntities();
     }
     Document newDocDebt = new Document
     {
         AccountID = accountid,
         Description = "پرداخت نقد فاکتور " + Inv.InvoiceID,
         Value = Inv.TotalPrice + Inv.Expenses - Inv.Discount,
         Date = Inv.Date,
         SetDate = Utilities.getCurrentPersianDate(),
         Debt_Credit = true,
         InvoiceID = Inv.InvoiceID
     };
     db.Documents.AddObject(newDocDebt);
     db.SaveChanges();
 }
Exemplo n.º 8
0
 public InvoiceSaleForm()
 {
     timestamp = Utilities.getCurrentTimeStamp();
     this.total = 0L;
     this.discount = 0L;
     this.InitializeComponent();
     this.edit = false;
     this.db = new StoreDBEntities();
     this.InitializeForm();
     this.Font = MainForm.FORM_FONT;
     this.numDiscount.Minimum = 0m;
     this.numExpenses.Maximum = new decimal(9223372036854775807L);
     this.lblTimestamp.Text = timestamp.ToString();
    // T = new Thread(new ThreadStart(FillTable));
 }
Exemplo n.º 9
0
 public static void SaveInvoiceDocument(Invoice Inv)
 {
     var db = new StoreDBEntities();
     if (Inv.Sale && (Inv.TarafID < 0 || Inv.Paid))
         return;
     long accountid = 0;
     try
     {
         accountid = db.Accounts.AsEnumerable().First(x => x.DistributorID == Inv.TarafID).Id;
     }
     catch (InvalidOperationException)
     {
         Account newAcc = new Account
         {
             Name = Inv.Distributor.Name,
             Description = " ",
             CustomerID = Inv.Sale ? Inv.TarafID : 0,
             DistributorID = Inv.Sale ? 0 : Inv.TarafID,
             BankAccountID = 0
         };
         db.Accounts.AddObject(newAcc);
         db.SaveChanges();
         accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id;
         //db.AcceptAllChanges();
         //db = new StoreDBEntities();
     }
     Document newDocCred = new Document
     {
         AccountID = accountid,
         Description = "فاکتور "+ (Inv.Sale ? "ف" : "خ") +" شماره " + Inv.InvoiceID,
         Value = Inv.TotalPrice + Inv.Expenses - Inv.Discount,
         Date = Inv.Date,
         SetDate = Utilities.getCurrentPersianDate(),
         Debt_Credit = Inv.Sale ? true : false,
         InvoiceID = Inv.InvoiceID
     };
     db.Documents.AddObject(newDocCred);
     db.SaveChanges();
 }
Exemplo n.º 10
0
 private void MainForm_Load(object sender, System.EventArgs e)
 {
     base.WindowState = FormWindowState.Maximized;
     this.abrMainDate.SelectedDate = (System.DateTime.Now);
     this.ControlDailyCheques();
     this.Font = MainForm.FORM_FONT;
     this.menuStrip1.Font = new System.Drawing.Font(MainForm.FORM_FONT.FontFamily, 10f, System.Drawing.FontStyle.Bold);
     InputLanguage currentInputLanguage = InputLanguage.DefaultInputLanguage;
     for (int i = 0; i < InputLanguage.InstalledInputLanguages.Count; i++)
     {
         if (InputLanguage.InstalledInputLanguages[i].LayoutName == "Persian")
         {
             currentInputLanguage = InputLanguage.InstalledInputLanguages[i];
         }
     }
     InputLanguage.CurrentInputLanguage = currentInputLanguage;
     StoreDBEntities db = new StoreDBEntities();
     var tmpList = db.TempInvoices.ToList();
     for (int i = 0; i < tmpList.Count; i++)
     {
         db.TempInvoices.DeleteObject(tmpList[i]);
     }
     if (tmpList.Count > 0)
     {
         var itemsGrp = tmpList.GroupBy(x => x.TimeStamp).ToList();
         for (int i = 0; i < itemsGrp.Count; i++)
             (new InvoiceSaleForm(itemsGrp[i]){
                 MdiParent = this
             }).Show();
     }
     db.SaveChanges();
         
 }
Exemplo n.º 11
0
        private void btnCreateInvoice_Click(object sender, System.EventArgs e)
        {
            if (this.total == 0L)
            {
                FarsiMessage.Show("مجموع فاکتور صفر است", "", FarsiMessageBoxButtons.OK, FarsiMessageBoxIcons.Stop);
                return;
            }
            string selectedDateString = this.abrInvoiceDate.SelectedDateString;
            if (this.edit)
            {
                List<InvoiceItem> list = editInv.InvoiceItems.ToList<InvoiceItem>();
                for (int i = 0; i < list.Count; i++)
                {
                    long invItemId = list[i].ID;
                    this.db.InvoiceItems.DeleteObject(this.db.InvoiceItems.First((InvoiceItem x) => x.ID == invItemId));
                    long itemID = list[i].ItemID;
                    Item item = this.db.Items.First((Item x) => x.ItemID == itemID);
                    item.Available += list[i].Count;
                    
                }
                this.GenInvoiceID = this.editInv.InvoiceID;
                Invoice invoice = this.db.Invoices.First((Invoice x) => x.InvoiceID == this.GenInvoiceID);
                invoice.TarafID = (long)this.cmbCustomers.SelectedValue;
                invoice.Paid = (this.cmbCustomers.SelectedIndex <= 0 || !this.chkUnPaidInvoice.Checked);
                invoice.Discount = this.discount;
                invoice.TotalPrice = this.total;
                invoice.Expenses = this.expenses;
                invoice.Description = "";
                invoice.Date = this.abrInvoiceDate.SelectedDateString;
                this.db.Invoices.ApplyCurrentValues(invoice);
                this.db.SaveChanges();
                this.edit = false;
            }
            else
            {
                Invoice newInv = new Invoice()
                {
                    Sale = true,
                    TarafID = (long)this.cmbCustomers.SelectedValue,
                    Date = selectedDateString,
                    Paid = this.cmbCustomers.SelectedIndex == 0 || !this.chkUnPaidInvoice.Checked,
                    TotalPrice = this.total,
                    Discount = this.discount,
                    Expenses = this.expenses,
                    Description = ""
                };
                db.Invoices.AddObject(newInv);
                db.SaveChanges();
                GenInvoiceID = newInv.InvoiceID;
                
                long accountid = 0;
                if (cmbCustomers.SelectedIndex > 0)
                {
                    try
                    {
                        accountid = db.Accounts.First(x => x.CustomerID == (long)cmbCustomers.SelectedValue).Id;
                    }
                    catch (InvalidOperationException)
                    {
                        Account newAcc = new Account
                        {
                            Name = cmbCustomers.Text,
                            Description = " ",
                            DistributorID = 0,
                            CustomerID = (long)cmbCustomers.SelectedValue,
                            BankAccountID = 0
                        };
                        db.Accounts.AddObject(newAcc);
                        db.SaveChanges();
                        accountid = db.Accounts.OrderByDescending(x => x.Id).First().Id;
                    }
                    try
                    {
                        Document docEdit = db.Documents.First(x => x.InvoiceID == GenInvoiceID && x.Debt_Credit == true);
                        docEdit.Value = total - discount;
                        db.Documents.ApplyCurrentValues(docEdit);
                    }
                    catch
                    {
                        Document newDocDebt = new Document
                        {
                            AccountID = accountid,
                            Description = "فاکتور ف " + GenInvoiceID,
                            Value = total - discount,
                            Date = abrInvoiceDate.SelectedDateString,
                            SetDate = Utilities.getCurrentPersianDate(),
                            Debt_Credit = true,
                            InvoiceID = GenInvoiceID
                        };
                        db.Documents.AddObject(newDocDebt);
                    }
                    try
                    {
                        Document docPayEdit = db.Documents.First(x => x.InvoiceID == GenInvoiceID && x.Debt_Credit == false);
                        if (!this.chkUnPaidInvoice.Checked)
                        {
                            docPayEdit.Value = total - discount;
                            db.Documents.ApplyCurrentValues(docPayEdit);
                        }
                        else
                            db.Documents.DeleteObject(docPayEdit);
                    }
                    catch
                    {
                        if (!this.chkUnPaidInvoice.Checked)
                        {
                            Document newDocPay = new Document
                            {
                                AccountID = accountid,
                                Description = "پرداخت فاکتور فروش " + GenInvoiceID,
                                Value = total - discount,
                                Date = abrInvoiceDate.SelectedDateString,
                                SetDate = Utilities.getCurrentPersianDate(),
                                Debt_Credit = false,
                                InvoiceID = GenInvoiceID
                            };
                            db.Documents.AddObject(newDocPay);
                        }
                    }
                    db.SaveChanges();
                }
                ClearTempItems();
                timestamp = Utilities.getCurrentTimeStamp();
                lblTimestamp.Text = timestamp.ToString();
            }
            this.daily = this.dailyTransactionTableAdapter.GetData().ToList<StoreDBDataSet.DailyTransactionRow>().FirstOrDefault((StoreDBDataSet.DailyTransactionRow x) => x.Description == "اضافه دریافت فاکتور " + GenInvoiceID);
            if(daily != null)
                this.dailyTransactionTableAdapter.DeleteByID(this.daily.ID);
//            if (numExpenses.Value>0)
//                this.dailyTransactionTableAdapter.Insert(selectedDateString, this.expenses, false, "اضافه دریافت فاکتور " + this.GenInvoiceID);
//            else if (this.discount > 0L)
//                this.dailyTransactionTableAdapter.Insert(selectedDateString, this.discount, true, "تخفیف فاکتور " + this.GenInvoiceID);
            for (int i = 0; i < this.lstTotal.Items.Count; i++)
            {
                long num2 = long.Parse(this.lstTotal.Items[i].SubItems[0].Text);
                this.invoiceItemTableAdapter.Insert(this.GenInvoiceID, num2, int.Parse(this.lstTotal.Items[i].SubItems[2].Text.Replace(",", "")), int.Parse(this.lstTotal.Items[i].SubItems[3].Text));
                //this.itemTableAdapter.GetDataByItemID(num2);
                this.itemTableAdapter.UpdateAvailable(int.Parse(this.lstTotal.Items[i].SubItems[3].Text), num2);
            }
            if (this.cmbCustomers.SelectedIndex > 0)
            {
                StoreDBDataSet.CustomerRow customerRow = this.customerTableAdapter.GetData().First((StoreDBDataSet.CustomerRow x) => x.ID == (long)this.cmbCustomers.SelectedValue);
                this.customerTableAdapter.UpdateByID(customerRow.Name, this.chkUnPaidInvoice.Checked ? (customerRow.Debt + this.total + this.expenses - this.discount) : customerRow.Debt, customerRow.LastPayment, selectedDateString, customerRow.ID);
                
            }
            if (this.chkReportOutput.Checked)
            {
                var rep = stiReport1.SaveToString();
                this.invoiceItemTableAdapter.FillByInvoiceID(this.storeDBDataSet.InvoiceItem, this.GenInvoiceID);
                this.itemTableAdapter.Fill(this.storeDBDataSet.Item);
                this.invoiceTableAdapter.Fill(this.storeDBDataSet.Invoice);
                this.customerTableAdapter.Fill(this.storeDBDataSet.Customer);
                this.stiReport1.RegData(this.storeDBDataSet);
                this.stiReport1.Show(false);
                stiReport1.LoadFromString(rep);
            }
            //this.FillTable(this.itemTableAdapter.GetData());
            db = new StoreDBEntities();
            this.lstTotal.Items.Clear();
            this.lblTotalPrice.Text = "";
            this.ComputeTotal(false);
            this.numDiscount.Value = 0m;
            this.numExpenses.Value = 0m;
            this.cmbCustomers.SelectedIndex = 0;
            this.chkUnPaidInvoice.Checked = false;
            this.txtItemNameID.Clear();
            this.txtItemNameID.Focus();
        }
Exemplo n.º 12
0
 private void SaveDocumentToolStripMenuItem_Click(object sender, EventArgs e)
 {
     StoreDBEntities db = new StoreDBEntities();
     ChequeAddForm.SaveDocument(
         db.Cheques.AsEnumerable().First(x=>x.ID == long.Parse(lstCheques.SelectedItems[0].SubItems[0].Text)));
 }
Exemplo n.º 13
0
        private void btnSavePayment_Click(object sender, System.EventArgs e)
        {
            if (this.txtPaymentPrice.TextLength > 0)
            {
                if (this.cmbPaymentTypes.Text == "موجودی")
                {
                    int i = 0;
                    while (i < this.lstPayments.Items.Count)
                    {
                        if (this.lstPayments.Items[i].SubItems[1].Text == "موجودی")
                        {
                            if (FarsiMessage.Show("موجودی قبلاً ثبت شده است. مقدار جدید برای موجودی امروز ثبت شود؟", "تکراری", FarsiMessageBoxButtons.YesNo,FarsiMessageBoxIcons.Question) == DialogResult.Yes)
                            {
                                this.dailyTransactionTableAdapter.DeleteByID(long.Parse(this.lstPayments.Items[i].SubItems[0].Text));
                                this.lstPayments.Items.RemoveAt(i);
                                break;
                            }
                            return;
                        }
                        else
                        {
                            i++;
                        }
                    }
                }
                long newID = (long)this.dailyTransactionTableAdapter.InsertQuery(this.abrDateToday.SelectedDateString, long.Parse(this.txtPaymentPrice.Text), true, this.txtPaymentDescription.Text);
                if (this.cmbBankAccounts.Visible)
                {
                    this.bankAccountTableAdapter.IncreaseBalance(long.Parse(this.txtPaymentPrice.Text), (long)this.cmbBankAccounts.SelectedValue);
                }
                
                //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                if(cmbPaymentTypes.Text.Contains("واریز به حساب"))
                {
                    StoreDBEntities DB = new StoreDBEntities();
                    long bankID = 0;
                    try
                    {
                        bankID = DB.Accounts.First(x => x.BankAccountID == (long)cmbBankAccounts.SelectedValue).Id;
                    }
                    catch (InvalidOperationException)
                    {
                        Account newAcc = new Account
                        {
                            Name = "بانک " + cmbBankAccounts.Text,
                            Description = " ",
                            CustomerID = 0,
                            DistributorID = 0,
                            BankAccountID = (long)cmbBankAccounts.SelectedValue
                        };
                        DB.Accounts.AddObject(newAcc);
                        DB.SaveChanges();
                        bankID = DB.Accounts.OrderByDescending(x => x.Id).First().Id;
                    }
                    Document newBankDoc = new Document
                    {
                        AccountID = bankID,
                        Description = "واریز نقد",
                        Value = long.Parse(txtPaymentPrice.Text),
                        Date = abrDateToday.SelectedDateString,
                        SetDate = Utilities.getCurrentPersianDate(),
                        Debt_Credit = true,
                        TransactionID = newID
                    };
                    DB.Documents.AddObject(newBankDoc);
                    DB.SaveChanges();
                }
                //\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                this.txtPaymentPrice.Clear();
                this.DateChanged();
                this.FixList();

                return;
            }
            this.errorProvider.SetError(this.lblPaymentPrice, "مبلغ وارد نشده است");
        }
Exemplo n.º 14
0
 private void InvoiceManageForm_Activated(object sender, System.EventArgs e)
 {
     this.db = new StoreDBEntities();
 }
Exemplo n.º 15
0
 private void FixCounts()
 {
     StoreDBEntities storeDBEntities = new StoreDBEntities();
     System.Collections.Generic.List<Item> list = storeDBEntities.Items.ToList<Item>();
     this.progressBar1.Maximum = list.Count;
     for (int i = 0; i < list.Count; i++)
     {
         try
         {
             this.progressBar1.Value = i;
             long id = list[i].ItemID;
             string name = list[i].Name;
             long purchase = storeDBEntities.InvoiceItems.Where(x => x.Invoice.Sale == false && x.ItemID == id).Sum(x => x.Count);
             long sale = storeDBEntities.InvoiceItems.Where(x => x.Invoice.Sale == true && x.ItemID == id).Sum(x => x.Count);
             Item item = storeDBEntities.Items.First((Item x) => x.ItemID == id);
             item.Available = Convert.ToInt32(purchase - sale);
             DB.Items.ApplyCurrentValues(item);
         }
         catch (InvalidOperationException) { }
     }
     storeDBEntities.SaveChanges();
     this.btnFixItemCounts.Enabled = true;
     this.progressBar1.Value = 0;
     this.T.Abort();
 }
Exemplo n.º 16
0
 //private bool changed;
 //private Thread T;
 public InvoiceBuyForm()
 {
     this.total = 0L;
     this.discount = 0L;
     this.submitted = false;
     this.InitializeComponent();
     CheckForIllegalCrossThreadCalls = false;
     this.db = new StoreDBEntities();
     this.cmbDistributor.DataSource = (
         from x in this.db.Distributors
         orderby x.Name
         select x).ToList<Distributor>();
     this.cmbDistributor.ValueMember = "ID";
     this.cmbDistributor.DisplayMember = "Name";
    
     this.edit = false;
     //T = new Thread(new ThreadStart(FillTable));
 }
Exemplo n.º 17
0
 public static void SaveDocument(Cheque chq)
 {
     var DB = new StoreDBEntities();
     long accountid = 0;
     try
     {
         accountid = DB.Accounts.First(x => x.DistributorID == chq.Invoice.TarafID).Id;
     }
     catch (InvalidOperationException)
     {
         Account newAcc = new Account
         {
             Name = chq.Invoice.Distributor.Name,
             Description = " ",
             CustomerID = 0,
             DistributorID = chq.Invoice.TarafID,
             BankAccountID = 0
         };
         DB.Accounts.AddObject(newAcc);
         DB.SaveChanges();
         accountid = DB.Accounts.OrderByDescending(x => x.Id).First().Id;
     }
     Document newDoc = new Document
     {
         AccountID = accountid,
         Description = "چک شماره" + chq.CheckNum + " بابت فاکتور خ شماره " + chq.InvoiceID,
         Value = chq.Price,
         Date = chq.Invoice.Date,
         SetDate = Utilities.getCurrentPersianDate(),
         Debt_Credit = true,
         ChequeID = chq.ID
     };
     DB.Documents.AddObject(newDoc);
     DB.SaveChanges();
     //--------------------------
     long bankID = 0;
     try
     {
         bankID = DB.Accounts.First(x => x.BankAccountID == chq.BankAccount.ID).Id;
     }
     catch (InvalidOperationException)
     {
         Account newAcc = new Account
         {
             Name = "بانک " + chq.BankAccount.BankName,
             Description = " ",
             CustomerID = 0,
             DistributorID = 0,
             BankAccountID = chq.BankAccount.ID
         };
         DB.Accounts.AddObject(newAcc);
         DB.SaveChanges();
         bankID = DB.Accounts.OrderByDescending(x => x.Id).First().Id;
     }
     Document newBankDoc = new Document
     {
         AccountID = bankID,
         Description = "چک شماره" + chq.CheckNum + " در وجه " + chq.Invoice.Distributor.Name,
         Value = chq.Price,
         Date = chq.Date,
         SetDate = Utilities.getCurrentPersianDate(),
         Debt_Credit = false,
         ChequeID = chq.ID
     };
     DB.Documents.AddObject(newBankDoc);
     DB.SaveChanges();
 }
Exemplo n.º 18
0
 private void ItemSearchForm_Activated(object sender, System.EventArgs e)
 {
     this.db = new StoreDBEntities();
 }
Exemplo n.º 19
0
 public AccountsManageForm()
 {
     this.DB = new StoreDBEntities();
     this.edit = false;
     this.InitializeComponent();
 }
Exemplo n.º 20
0
 private void AccountsManageForm_Activated(object sender, System.EventArgs e)
 {
     this.DB = new StoreDBEntities();
 }
Exemplo n.º 21
0
 public ChequeAddForm()
 {
     this.certain = false;
     this.edit = false;
     this.InitializeComponent();
     this.DB = new StoreDBEntities();
     this.Font = MainForm.FORM_FONT;
     this.cmbAccountants.DataSource = (
         from x in this.DB.Distributors
         orderby x.Name
         select x).ToList<Distributor>();
     this.bankAccountTableAdapter.Fill(this.storeDBDataSet.BankAccount);
     this.abrChequeDate.SelectedDate = (System.DateTime.Now);
     if (!this.certain)
     {
         this.InitializeForm();
         this.cmbAccountants_SelectedIndexChanged(null, null);
         this.cmbBankNameAccount_SelectedIndexChanged(null, null);
         this.abrChequeDate.SelectedDate = (System.DateTime.Now);
     }
 }
Exemplo n.º 22
0
 private void ChequeAddForm_Activated(object sender, System.EventArgs e)
 {
     this.DB = new StoreDBEntities();
 }
Exemplo n.º 23
0
        private void btnReturnItem_Click(object sender, System.EventArgs e)
        {
            List<long> invIDs = new List<long>();
            for (int i = 0; i < this.lstInvoiceItems.SelectedIndices.Count; i++)
            {
                long invid = long.Parse(this.lstItemArray[lstInvoiceItems.SelectedIndices[i]].SubItems[4].Text);
                if (!invIDs.Contains(invid))
                    invIDs.Add(invid);
            }
            for (int i = 0; i < invIDs.Count; i++)
            {
                Invoice invoice = this.db.Invoices.AsEnumerable().First((Invoice x) => x.InvoiceID == invIDs[i]);
                if (invoice.Sale)
                    (new InvoiceSaleForm(invoice)).ShowDialog();
                else
                    new InvoiceBuyForm(invoice).ShowDialog();
            }
            db = new StoreDBEntities();
            this.changed = true;
            //invItm.Count -= (int)numCount.Value;
            //invoice.TotalPrice -= (int)numCount.Value * price;
            //db.InvoiceItems.ApplyCurrentValues(invItm);
            //db.Invoices.ApplyCurrentValues(invoice);

            //Item item = this.db.Items.First((Item x) => x.ItemID == itemid);
            //if (invoice.Sale)
            //{
            //    item.Available += (this.rdbtnReturnAll.Checked ? count : ((int)this.numReturn.Value));
            //}
            //else
            //{
            //    item.Available -= (this.rdbtnReturnAll.Checked ? count : ((int)this.numReturn.Value));
            //}
            //db.Items.ApplyCurrentValues(item);

            //if (this.rdbtnSale.Checked && !invoice.Paid)
            //{
            //    long custID = invoice.TarafID;
            //    Customer customer = this.db.Customers.First((Customer x) => x.ID == custID);
            //    customer.Debt -= (long)(count * price);
            //    db.Customers.ApplyCurrentValues(customer);
            //}
            //this.db.SaveChanges();
        }
Exemplo n.º 24
0
        private void FillTable()
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                StoreDBEntities storeDBEntities = new StoreDBEntities();
                this.listViewItems = (
                    from x in storeDBEntities.Items
                    join y in
                        from v in storeDBEntities.InvoiceItems
                        where !v.Invoice.Sale && v.Price > 0
                        select v on x.ItemID equals y.ItemID
                    select new ListItem
                    {
                        ItemID = x.ItemID,
                        ItemName = x.Name,
                        Available = x.Available,
                        SellPrice = x.SellPrice,
                        LastBuy = y.Price,
                        BuyDate = y.Invoice.Date
                    }).GroupBy((ListItem x) => x.ItemID, (long y, System.Collections.Generic.IEnumerable<ListItem> z) => (
                    from v in z
                    orderby v.BuyDate descending
                    select v).FirstOrDefault<ListItem>()).ToList<ListItem>();
                long[] ids = (
                    from x in storeDBEntities.Items
                    select x.ItemID).Except((
                    from v in storeDBEntities.InvoiceItems
                    where !v.Invoice.Sale && v.Price > 0
                    select v into x
                    select x.ItemID).Distinct<long>()).ToArray<long>();
                IQueryable<Item> source =
                    from x in storeDBEntities.Items
                    where ids.Contains(x.ItemID)
                    select x;
                this.notOnList = source.ToArray<Item>();
                while (true)
                {
                    if (!this.queryChanged)
                    {
                        System.Threading.Thread.Sleep(50);
                    }
                    else
                    {
                        this.lstItems.Items.Clear();
                        this.Cursor = Cursors.WaitCursor;
                        this.queryChanged = false;
                        long searchID = 0L;
                        string[] searchName = this.txtSearchName.Text.Split(" ".ToCharArray());
                        long.TryParse(this.txtSearchName.Text, out searchID);
                        System.Collections.Generic.List<ListItem> list = new System.Collections.Generic.List<ListItem>();
                        list.AddRange(this.listViewItems);
                        var extra = db.Item2ExtraID.FirstOrDefault(v => v.ExtraID == searchID);
                        if (this.rdbtnSearchName.Checked)
                        {
                            list = (
                                from x in list
                                where string.Concat(x.ItemID).Contains(this.txtSearchName.Text)
                               // || extra.ItemID == x.ItemID
                                || this.txtSearchName.Text.Split(" ".ToCharArray()).All((string y) => x.ItemName.Contains(y))
                                select x).ToList<ListItem>();
                        }
                        if (this.chkMaxCode.Checked && this.txtMaxCode.TextLength > 0)
                        {
                            list = (
                                from x in list
                                where x.ItemID < long.Parse(this.txtMaxCode.Text)
                                select x).ToList<ListItem>();
                        }
                        System.Collections.Generic.List<ListItem> list2 = (
                            from x in list
                            orderby x.ItemID
                            select x).ToList<ListItem>();
                        System.Collections.Generic.List<Item> list3 = (
                            from x in this.notOnList
                            where x.ItemID == searchID || searchName.All((string y) => x.Name.Contains(y))
                            orderby x.ItemID
                            select x).ToList<Item>();
                        for (int i = 0; i < list3.Count; i++)
                        {
                            list2.Add(new ListItem(list3[i].ItemID, list3[i].Name, list3[i].Available, list3[i].SellPrice, 0, Utilities.START_DATE));
                        }
                        this.lvi = new ListViewItem[list2.Count];
                        int num = 0;
                        while (num < this.lvi.Length && !this.queryChanged)
                        {
                            ListItem listItem = list2[num];
                            this.lvi[num] = new ListViewItem(new string[]
							{
								listItem.ItemID.ToString(),
								listItem.ItemName.ToString(),
								listItem.Available.ToString(),
								listItem.SellPrice.ToString("0,0"),
								listItem.LastBuy.ToString("0,0")
							});
                            num++;
                        }
                        if (!this.queryChanged)
                        {
                            this.lstItems.Items.Clear();
                            this.lstItems.Items.AddRange(this.lvi);
                        }
                        this.Cursor = Cursors.Default;
                    }
                }
            }
            catch
            {
            }
        }
Exemplo n.º 25
0
 private void btnEditInvoice_Click(object sender, System.EventArgs e)
 {
     //timer1.Enabled = false;
     try
     {
         long invID = long.Parse(this.lstInvoices.Items[this.lstInvoices.SelectedIndices[0]].SubItems[0].Text);
         Invoice invoice = this.db.Invoices.First(
             (Invoice x) => x.InvoiceID == invID);
         if (this.lstInvoices.SelectedIndices.Count > 0)
         {
             if (this.lstInvoices.Items[this.lstInvoices.SelectedIndices[0]].SubItems[5].Text == "فروش")
             {
                 new InvoiceSaleForm(invoice).Show();
             }
             else
             {
                 new InvoiceBuyForm(invoice).Show();
             }
         }
         this.filterChanged = true;
         this.db = new StoreDBEntities();
         this.ListInvoices();
     }
     catch (System.InvalidOperationException)
     {
         //FarsiMessage.Show("فاکتور در لیست موجود نیست");
     }
     //timer1.Enabled = true;
 }
Exemplo n.º 26
0
        private void Calculate()
        {
            StoreDBEntities db = new StoreDBEntities();
            this.btnCalculateSum.Enabled = false;
            if (this.abrEndDate.SelectedDateString.CompareTo(this.abrStartDate.SelectedDateString) <= 0)
            {
                FarsiMessage.Show("تاریخ شروع و پایان صحیح انتخاب نشده اند", "خطا", FarsiMessageBoxButtons.OK,FarsiMessageBoxIcons.Stop);
                this.T.Abort();
                return;
            }
            StoreDBDataSet.ItemDataTable items = this.itemTableAdapter.GetData();
            this.prgCalculate.Maximum = items.Count;
            StoreDBDataSet.ItemDataTable itemsEndDate = (StoreDBDataSet.ItemDataTable)items.Copy();
            StoreDBDataSet.ItemDataTable itemsStartDate = (StoreDBDataSet.ItemDataTable)items.Copy();
            var invoiceItems = db.InvoiceItems.Join(db.Invoices, x => x.InvoiceID, y => y.InvoiceID, (z, v) => new InvoiceItemOnInvoice{
                ID = z.ID,
                InvoiceID = z.InvoiceID,
                ItemID = z.ItemID,
                Price = z.Price,
                Count = z.Count,
                Date = v.Date,
                Sale = v.Sale,
                Paid = v.Paid,
                TotalPrice = v.TotalPrice
            }).OrderByDescending(o=>o.Date).ToArray();
            for (int i = 0; i < items.Count; i++)
            {
                this.prgCalculate.Value = i;
                InvoiceItemOnInvoice []itemSaleAfterStartDate =  
                    invoiceItems.Where(x=>x.ItemID == items[i].ItemID && x.Sale == true && x.Date.CompareTo(abrStartDate.SelectedDateString)>0).ToArray();
                InvoiceItemOnInvoice []itemBuyAfterStartDate =
                    invoiceItems.Where(x => x.ItemID == items[i].ItemID && x.Sale == false && x.Date.CompareTo(abrStartDate.SelectedDateString) > 0).ToArray();
                InvoiceItemOnInvoice []itemAllBuys =
                    invoiceItems.Where(x => x.ItemID == items[i].ItemID && x.Sale == false).ToArray();
                if (itemAllBuys.Length > 0)
                {
                    InvoiceItemOnInvoice itemLastbuy = itemAllBuys[itemAllBuys.Length - 1];
                    if (itemLastbuy.Date.CompareTo(this.abrStartDate.SelectedDateString) < 0)
                    {                        //اولین خرید قبل از تاریخ شروع
                        itemsEndDate[i].Available += itemSaleAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) > 0).Sum(x => x.Count);
                        //int j = 0;
                        //while (j < itemSaleAfterStartDate.Length && itemSaleAfterStartDate[j].Date.CompareTo(this.abrEndDate.SelectedDateString) > 0)
                        //{
                        //    itemsEndDate[i].Available += itemSaleAfterStartDate[j].Count;
                        //    j++;
                        //}
                        itemsEndDate[i].Available -= itemBuyAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) > 0).Sum(x => x.Count);
                        //int k = 0;
                        //while (k < itemBuyAfterStartDate.Length && itemBuyAfterStartDate[k].Date.CompareTo(this.abrEndDate.SelectedDateString) > 0)
                        //{
                        //    itemsEndDate[i].Available -= itemBuyAfterStartDate[k].Count;
                        //    k++;
                        //}
                        itemsStartDate[i].Available = itemsEndDate[i].Available;
                        itemsStartDate[i].Available += itemSaleAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) <= 0
                            && x.Date.CompareTo(this.abrStartDate.SelectedDateString) > 0).Sum(x => x.Count);
                        //while (j < itemSaleAfterStartDate.Count)
                        //{
                        //    itemsStartDate[i].Available += itemSaleAfterStartDate[j].Count;
                        //    j++;
                        //}
                        itemsStartDate[i].Available -= itemBuyAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) <= 0
                            && x.Date.CompareTo(this.abrStartDate.SelectedDateString) > 0).Sum(x => x.Count);
                        //while (k < itemBuyAfterStartDate.Count)
                        //{
                        //    itemsStartDate[i].Available -= itemBuyAfterStartDate[k].Count;
                        //    k++;
                        //}
                    }
                    else
                    {                        //اولین خرید بعد از تاریخ شروع
                        if (itemLastbuy.Date.CompareTo(this.abrEndDate.SelectedDateString) > 0)
                        {                        //اولین خرید بعد از تاریخ پایان
                            itemsEndDate[i].Available = 0;
                            itemsStartDate[i].Available = 0;
                        }
                        else
                        {                        //اولین خرید بین تاریخ شروع و پایان
                            itemsEndDate[i].Available += itemSaleAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) > 0).Sum(x => x.Count);
                            //int l = 0;
                            //while (l < itemSaleAfterStartDate.Count && itemSaleAfterStartDate[l].Date.CompareTo(this.abrEndDate.SelectedDateString) > 0)
                            //{
                            //    itemsEndDate[i].Available += itemSaleAfterStartDate[l].Count;
                            //    l++;
                            //}
                            itemsEndDate[i].Available -= itemBuyAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) > 0).Sum(x => x.Count);
                            //int m = 0;
                            //while (m < itemBuyAfterStartDate.Count && itemBuyAfterStartDate[m].Date.CompareTo(this.abrEndDate.SelectedDateString) > 0)
                            //{
                            //    itemsEndDate[i].Available -= itemBuyAfterStartDate[m].Count;
                            //    m++;
                            //}
                            itemsStartDate[i].Available = 0;
                            //itemsStartDate[i].Available = itemsEndDate[i].Available;
                            //itemsStartDate[i].Available += itemSaleAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) <= 0).Sum(x => x.Count);
                            ////while (l < itemSaleAfterStartDate.Count)
                            ////{
                            ////    itemsStartDate[i].Available += itemSaleAfterStartDate[l].Count;
                            ////    l++;
                            ////}
                            //itemsStartDate[i].Available -= itemBuyAfterStartDate.Where(x => x.Date.CompareTo(this.abrEndDate.SelectedDateString) <= 0).Sum(x => x.Count);
                            ////while (m < itemBuyAfterStartDate.Count)
                            //{
                            //    itemsStartDate[i].Available -= itemBuyAfterStartDate[m].Count;
                            //    m++;
                            //}
                        }
                    }
                }
                else
                {
                    itemsEndDate[i].Available = 0;
                    itemsStartDate[i].Available = 0;
                }
            }
            this.prgCalculate.Value = 0;
            List<ListViewItem> list = new List<ListViewItem>();
            for (int n = 0; n < itemsEndDate.Count; n++)
            {
                if (itemsEndDate[n].Available <= 0)
                {
                    itemsEndDate.Rows.RemoveAt(n);
                    n--;
                }
                else
                {
                    try
                    {
                        string text = invoiceItems.First(x => x.ItemID == itemsEndDate[n].ItemID &&
                            x.Sale == false && x.Date.CompareTo(this.abrEndDate.SelectedDateString)<0  && x.Price > 0 && x.Count > 0).Price.ToString();
                        list.Add(new ListViewItem(new string[]{
							itemsEndDate[n].ItemID.ToString(),
							itemsEndDate[n].Name.ToString(),
							itemsEndDate[n].Available.ToString(),
							text
						}));
                    }
                    catch (System.InvalidOperationException)
                    {
                    }
                }
            }
            this.lstAvailableAtEndDate.Items.Clear();
            this.lstAvailableAtEndDate.Items.AddRange(list.ToArray());
            Utilities.ListViewFixColumns(this.lstAvailableAtEndDate);
            StoreDBDataSet.ViewInvoiceItemOnInvoiceDataTable dataByDateSale = this.viewInvoiceItemOnInvoiceTableAdapter.GetDataByDateSale(
                new bool?(true), this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString);
            this.viewInvoiceItemOnInvoiceTableAdapter.GetDataByDateSale(new bool?(false), this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString);
            System.Collections.Generic.List<ListViewItem> list2 = new System.Collections.Generic.List<ListViewItem>();
            for (int num = 0; num < itemsStartDate.Count; num++)
            {
                if (itemsStartDate[num].Available <= 0)
                {
                    itemsStartDate.Rows.RemoveAt(num);
                    num--;
                }
                else
                {
                    try
                    {
                        StoreDBDataSet.ViewInvoiceItemOnInvoiceRow viewInvoiceItemOnInvoiceRow3 = this.viewInvoiceItemOnInvoiceTableAdapter.GetDataByItemIDDateSale(itemsStartDate[num].ItemID, new bool?(false), Utilities.START_DATE, this.abrStartDate.SelectedDateString).First((StoreDBDataSet.ViewInvoiceItemOnInvoiceRow h) => h.Count > 0 && h.Price > 0);
                        string text = invoiceItems.First(x => x.ItemID == itemsStartDate[num].ItemID &&
                            x.Sale == false && x.Date.CompareTo(this.abrStartDate.SelectedDateString) < 0 && x.Price > 0 && x.Count > 0).Price.ToString();
                        list2.Add(new ListViewItem(new string[]
						{
							itemsStartDate[num].ItemID.ToString(),
							itemsStartDate[num].Name.ToString(),
							itemsStartDate[num].Available.ToString(),
							text
						}));
                    }
                    catch (System.InvalidOperationException)
                    {
                    }
                }
            }
            this.lstAvailableAtStartDate.Items.Clear();
            this.lstAvailableAtStartDate.Items.AddRange(list2.ToArray());
            Utilities.ListViewFixColumns(this.lstAvailableAtStartDate);
            StoreDBDataSet.DailyTransactionDataTable dataByCostsPayment = this.dailyTransactionTableAdapter.GetDataByCostsPayment(this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString);
            this.bills = 0L;
            this.personal = 0L;
            this.salary = 0L;
            this.others = 0L;
            for (int num2 = 0; num2 < dataByCostsPayment.Count; num2++)
            {
                if (dataByCostsPayment[num2].Description.Contains("قبض"))
                {
                    this.bills += dataByCostsPayment[num2].Price;
                }
                else
                {
                    if (dataByCostsPayment[num2].Description.Contains("شخصی"))
                    {
                        this.personal += dataByCostsPayment[num2].Price;
                    }
                    else
                    {
                        if (dataByCostsPayment[num2].Description.Contains("حقوق"))
                        {
                            this.salary += dataByCostsPayment[num2].Price;
                        }
                        else
                        {
                            this.others += dataByCostsPayment[num2].Price;
                        }
                    }
                }
            }
            long num3 = 0L;
            long num4 = 0L;
            for (int num5 = 0; num5 < this.lstAvailableAtStartDate.Items.Count; num5++)
            {
                num3 += long.Parse(this.lstAvailableAtStartDate.Items[num5].SubItems[3].Text) * long.Parse(this.lstAvailableAtStartDate.Items[num5].SubItems[2].Text);
            }
            this.lblTotalStartDate.Text = num3.ToString("0,0");
            for (int num6 = 0; num6 < this.lstAvailableAtEndDate.Items.Count; num6++)
            {
                num4 += long.Parse(this.lstAvailableAtEndDate.Items[num6].SubItems[3].Text) * long.Parse(this.lstAvailableAtEndDate.Items[num6].SubItems[2].Text);
            }
            this.lblTotalEndDate.Text = num4.ToString("0,0");
            this.payTotalSum = this.bills + this.personal + this.salary + this.others;
            this.lblPaymentTotalSum.Text = this.payTotalSum.ToString("0,0");
            this.lblTotalBills.Text = this.bills.ToString("0,0");
            this.lblTotalOtherPayment.Text = this.others.ToString("0,0");
            this.lblTotalPersonal.Text = this.personal.ToString("0,0");
            this.lblTotalSalary.Text = this.salary.ToString("0,0");
            StoreDBDataSet.ChequeDataTable dataByDatePaid = this.chequeTableAdapter.GetDataByDatePaid(this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString, true);
            long sunChequePaid = 0L;
            for (int num8 = 0; num8 < dataByDatePaid.Count; num8++)
            {
                sunChequePaid += (long)dataByDatePaid[num8].Price;
            }
            this.lblTotalCheques.Text = sunChequePaid.ToString("0,0");
            long num9 = 0;
            for (int num10 = 0; num10 < dataByDateSale.Count; num10++)
            {
                num9 += dataByDateSale[num10].Count * dataByDateSale[num10].Price;
            }
            this.lblTotalSales.Text = num9.ToString("0,0");
            long num11 = 0;
            StoreDBDataSet.ViewInvoiceItemOnInvoiceDataTable dataByDateSale2 = this.viewInvoiceItemOnInvoiceTableAdapter.GetDataByDateSale(new bool?(false), this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString);
            for (int num12 = 0; num12 < dataByDateSale2.Count; num12++)
            {
                num11 += dataByDateSale2[num12].Count * dataByDateSale2[num12].Price;
            }
            this.lblTotalBuy.Text = num11.ToString("0,0");
            long num13 = 0L;
            long num14 = 0L;
            StoreDBDataSet.InvoiceDataTable dataByDate = this.invoiceTableAdapter.GetDataByDate(this.abrStartDate.SelectedDateString, this.abrEndDate.SelectedDateString);
            for (int num15 = 0; num15 < dataByDate.Count; num15++)
            {
                if (dataByDate[num15].Sale)
                {
                    num14 += dataByDate[num15].Discount;
                }
                else
                {
                    num13 += dataByDate[num15].Discount;
                }
            }
            this.lblTotalBuyDiscount.Text = num13.ToString("0,0");
            this.lblTotalSaleDiscount.Text = num14.ToString("0,0");
            long num16 = num3 + (long)num11 - num13;
            long num17 = num16 - num4;
            long num18 = (long)num9 - num17 - num14;
            this.lblProfit.Text = (num18 - this.payTotalSum).ToString("0,0");
            this.lblProfitPercentage.Text = ((double)(100L * num18) / (double)num9).ToString();
            this.btnCalculateSum.Enabled = true;
            this.T.Abort();
        }
Exemplo n.º 27
0
 public InvoiceManageForm()
 {
     this.InitializeComponent();
     showSpecific = false;
     this.filterChanged = true;
     this.db = new StoreDBEntities();
     this.itemTableAdapter = new ItemTableAdapter();
 }
Exemplo n.º 28
0
        private void btnSaveDebt_Click(object sender, EventArgs e)
        {
            string selectedDate = ((MainForm)base.MdiParent).abrMainDate.SelectedDateString;
            StoreDBEntities storeDBEntities = new StoreDBEntities();
            long currDebt = (long)numCurrentDebt.Value;
            long newDebt = (long)numNewDebt.Value;
            if (newDebt == currDebt)
                return;
            else
            {
                long accountid = 0;
                long CustomID = long.Parse(txtCustomerID.Text);
                try
                {
                    accountid = storeDBEntities.Accounts.First(
                        x => x.CustomerID == CustomID).Id;
                    //MessageBox.Show("cust found"+accountid);
                }
                catch (InvalidOperationException)
                {
                    Account newAcc = new Account
                    {
                        Name = txtCustomerName.Text,
                        Description = " ",
                        CustomerID = CustomID,
                        DistributorID = 0,
                        BankAccountID = 0
                    };
                    storeDBEntities.Accounts.AddObject(newAcc);
                    storeDBEntities.SaveChanges();
                    accountid = storeDBEntities.Accounts.OrderByDescending(x => x.Id).First().Id;
                   // MessageBox.Show("cust made"+accountid);
                }

                if (newDebt > currDebt)
                {
                    this.dailyTransactionTableAdapter.Insert(
                    selectedDate,
                    newDebt - currDebt,
                    true,
                    "پرداخت وجه به " + this.txtCustomerName.Text);
                    Document newDoc = new Document()
                    {
                        AccountID = accountid,
                        Description = "وجه دستی",
                        Value = newDebt - currDebt,
                        Date = selectedDate,
                        SetDate = Utilities.getCurrentPersianDate(),
                        Debt_Credit = true
                    };
                    storeDBEntities.Documents.AddObject(newDoc);
                    storeDBEntities.SaveChanges();
                   // MessageBox.Show("doc + done"+newDoc.Id);
                }
                else if (newDebt < currDebt)
                {
                    this.dailyTransactionTableAdapter.Insert(
                    selectedDate,
                    currDebt - newDebt,
                    false,
                    "پرداخت بدهی توسط " + this.txtCustomerName.Text);
                    this.lstCustomers.SelectedItems[0].SubItems[3].Text = selectedDate;
                    if (newDebt != 0L)
                    {
                        if (FarsiMessage.Show("مبلغ بدهی جدید کاهش یافته است\n\nآیا تمایل دارید برای تغییر وضعیت پرداخت فاکتورهای این مشتری به بخش مدیریت فاکتورها بروید؟", "تسویه ناقص بدهی", FarsiMessageBoxButtons.YesNo, FarsiMessageBoxIcons.Question)
                            == DialogResult.Yes)
                            (new InvoiceManageForm(custID, true)).Show();
                    }
                    else
                    {
                        List<Invoice> invoices = storeDBEntities.Invoices.Where(
                             (Invoice x) => x.Paid == false && x.TarafID == custID && x.Sale == true).ToList();
                        for (int i = 0; i < invoices.Count; i++)
                        {
                            invoices[i].Paid = true;
                            storeDBEntities.Invoices.ApplyCurrentValues(invoices[i]);
                        }
                    }
                    Document newDoc = new Document
                    {
                        AccountID = accountid,
                        Description = "پرداخت نقد/با کارت",
                        Value = currDebt - newDebt,
                        Date = selectedDate,
                        SetDate = Utilities.getCurrentPersianDate(),
                        Debt_Credit = false
                    };
                    storeDBEntities.Documents.AddObject(newDoc);
                    
                    Customer cst = storeDBEntities.Customers.AsEnumerable().First(
                        x => x.ID == CustomID);
                    cst.Debt = newDebt;
                    cst.LastPayment = selectedDate;
                    storeDBEntities.Customers.ApplyCurrentValues(cst);
                    storeDBEntities.SaveChanges();
                  //  MessageBox.Show("doc - done"+newDoc.Id);
                  //  MessageBox.Show("debt reduced"+CustomID);
                }
            }
            InitializeForm();
        }
Exemplo n.º 29
0
        private void FixList()
        {
            StoreDBEntities storeDBEntities = new StoreDBEntities();

            System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>();
            System.Collections.Generic.List<long> list2 = new System.Collections.Generic.List<long>();
            System.Collections.Generic.List<long> list3 = new System.Collections.Generic.List<long>();
            System.Collections.Generic.List<DailyTransaction> list4 = (
                from x in storeDBEntities.DailyTransactions
                orderby x.Date
                select x).ToList<DailyTransaction>();
            for (int i = 0; i < list4.Count; i++)
            {
                if (!list.Contains(list4[i].Date))
                {
                    list.Add(list4[i].Date);
                    list2.Add(0L);
                    list3.Add(0L);
                }
                if (list4[i].Payment)
                {
                    System.Collections.Generic.List<long> list5;
                    int index;
                    (list5 = list2)[index = list.IndexOf(list4[i].Date)] = list5[index] + list4[i].Price;
                }
                else
                {
                    System.Collections.Generic.List<long> list6;
                    int index2;
                    (list6 = list3)[index2 = list.IndexOf(list4[i].Date)] = list6[index2] + list4[i].Price;
                }
            }
            ListViewItem[] array = new ListViewItem[list.Count];
            for (int j = 0; j < list.Count; j++)
            {
                long num = list2[j] - list3[j];
                array[j] = new ListViewItem(new string[]
				{
					list[j],
					list2[j].ToString("0,0"),
					list3[j].ToString("0,0"),
					((num > 0L) ? "+" : "") + num.ToString("0,0")
				});
                if (num != 0L)
                {
                    array[j].SubItems[3].ForeColor = System.Drawing.Color.OrangeRed;
                }
            }
            this.lstAllTrans.Items.Clear();
            this.lstAllTrans.Items.AddRange(array);
            lstAllTrans.EnsureVisible(lstAllTrans.Items.Count - 1);
            Utilities.ListViewFixColumns(lstAllTrans);
        }
Exemplo n.º 30
0
 private void DocumentsManageForm_Activated(object sender, System.EventArgs e)
 {
     try
     {
         this.db = new StoreDBEntities();
         if (this.db.Accounts.Count<Account>() != this.cmbAccounts.Items.Count)
         {
             this.cmbAccounts.DataSource = (
                 from x in this.db.Accounts
                 orderby x.Name
                 select x).ToList<Account>();
         }
         this.cmbAccounts.SelectedIndex = this.selected;
     }
     catch
     {
     }
     this.UpdateList();
 }