示例#1
0
        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)// && e.Modifiers == Keys.Control)
            {
                if (MessageBox.Show("Delete invoice?", "Confirmation", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }

                DataAccess.SaleInvoice currentRow = (DataAccess.SaleInvoice)gridView1.GetFocusedRow();

                if (currentRow.Flag == 1)
                {
                    MessageBox.Show("You can not delete closed invoice", "Delete Invoice", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                db.SaleInvoices.Remove(currentRow);
                if (db.SaveChanges() > 0)
                {
                    MainScreen parent = (MainScreen)this.Parent.Parent.Parent.Parent;

                    parent.ShowMessageInStatusBar("Item Deleted", 9000);
                }
            }
        }
示例#2
0
        private void DoInvoice(bool print)
        {
            DataAccess.SaleInvoice invoice = new DataAccess.SaleInvoice();
            invoice.Date    = DateTime.Now;
            invoice.UserID  = Convert.ToInt32(UserData.Default.UserID);
            invoice.Remarks = "Sale";

            invoice.BranchID = branchID;
            invoice.Flag     = 0;

            db.SaleInvoices.Add(invoice);
            //I use a trigger to update inventory

            foreach (var item in details)
            {
                item.SaleInvoiceID = invoice.ID;
                invoice.SaleInvoiceDetails.Add(item);
            }
            invoice.Total    = Convert.ToDecimal(txtInvoiceTotal.Text);
            invoice.Discount = Convert.ToDecimal(txtDiscount.Text);
            int savedRows = db.SaveChanges();

            if (savedRows > 0)
            {
                invoice.Flag = 1;//To call trigger
                savedRows    = db.SaveChanges();
                if (print)
                {
                    DoPrint(invoice.ID);
                }
            }
        }
示例#3
0
        private void CalculateInventory_Load(object sender, EventArgs e)
        {
            try
            {
                var item_list = db.Items.ToList();
                itemBindingSource.DataSource = item_list;
                DataAccess.SaleInvoice invoice = db.SaleInvoices.Where(s => s.ID == SaleInvoiceId).SingleOrDefault();

                ////foreach (var item in item_list)
                ////{
                ////    var InventoryList = db.vw_Inventory.Where(s => s.ItemID == item.ID);

                ////    foreach (var invnt in InventoryList)
                ////    {
                ////        DataAccess.SaleInvoiceDetail saleDetails = db.SaleInvoiceDetails.Create();
                ////        saleDetails.SaleInvoiceID = SaleInvoiceId;
                ////        saleDetails.CurrentQuanitity = invnt.CurrentQuanity;
                ////        saleDetails.InventoryID = invnt.ID;
                ////        saleDetails.ItemID = item.ID;
                ////        saleDetails.PurchaseQuantity = invnt.ReceiveQuantity;
                ////        saleDetails.Quanitity = invnt.ReceiveQuantity;
                ////        saleDetails.Remarks = "Inv";
                ////        saleDetails.UnitPrice = invnt.SalePrice;

                ////        invoice.SaleInvoiceDetails.Add(saleDetails);

                ////    }
                ////}
                saleInvoiceDetailBindingSource.DataSource = invoice.SaleInvoiceDetails;
            }
            catch (Exception ex)
            {
                ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null);
            }
        }
示例#4
0
 private void gridView1_EditFormShowing(object sender, EditFormShowingEventArgs e)
 {
     if (gridView1.IsDataRow(e.RowHandle))
     {
         DataAccess.SaleInvoice currentRow = (DataAccess.SaleInvoice)gridView1.GetFocusedRow();
         if (currentRow.Flag == 1) //Clased Invoice
         {
             e.Allow = false;
             MessageBox.Show("You can not update closed invoice", "Closed Invoice", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
 }
示例#5
0
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            try
            {
                //Add or update items
                if (e.ClickedItem == invoiceDetailsToolStripMenuItem)
                {
                    DataAccess.SaleInvoice invoice = (DataAccess.SaleInvoice)gridView1.GetFocusedRow();

                    //if (invoice.Flag == 1) //Clased Invoice
                    //{
                    //    MessageBox.Show("You can not update closed invoice", "Update Invoice", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    //    return;
                    //}

                    new SaleInvoiceForm(invoice, false, SaleInvoiceType.Sale).ShowDialog();
                }

                //Close invoice
                if (e.ClickedItem == closeToolStripMenuItem)
                {
                    ////DataAccess.SaleInvoice currentRow = (DataAccess.SaleInvoice)gridView1.GetFocusedRow();
                    ////if(currentRow.Flag ==1)
                    ////{
                    ////    MessageBox.Show("Invoice already closed", "Closed Invoice", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    ////    return;
                    ////}

                    ////if(currentRow.PurchaseInvoiceDetails.Count==0)
                    ////{
                    ////    MessageBox.Show("You can not close invoice has no items", "Closed Invoice", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                    ////    return;

                    ////}

                    ////if (MessageBox.Show("Close invoice ?", "Close invoice", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    ////{
                    ////    currentRow.Flag = 1;
                    ////    if (db.SaveChanges() > 0)
                    ////    {
                    ////        MainScreen parent = (MainScreen)this.Parent.Parent.Parent.Parent;
                    ////        parent.ShowMessageInStatusBar("Invoice closed", 9000);
                    ////    }
                    ////}
                }
            }
            catch (Exception ex)
            {
                ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null);
            }
        }
示例#6
0
        private void btnNewInvoice_Click(object sender, EventArgs e)
        {
            try
            {
                DataAccess.SaleInvoice newInvoice = db.SaleInvoices.Create();

                new SaleInvoiceForm(newInvoice, true, SaleInvoiceType.Sale).ShowDialog();
            }
            catch (Exception ex)
            {
                ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null);
            }
        }
示例#7
0
        private void btnImportAircraft_Click(object sender, EventArgs e)
        {
            try
            {
                DataAccess.Inventory inventory;
                DataSet mainDS = ImportExcelXLS("C:\\Excel Files\\Reda1.xls", true);

                DataTable dtSale = mainDS.Tables[1];
                ////var resultsSale = from myRow in dtSale.AsEnumerable()
                ////              //where myRow.Field<int>("RowNo") == 1
                ////              select myRow;

                DataTable dtDetails = mainDS.Tables[3];



                DataAccess.SaleInvoice saleInvoice = null;
                int Salecounter    = 0;
                int Detailscounter = 0;
                foreach (DataRow item in mainDS.Tables[1].Rows)
                {
                    string i  = item["ID"].ToString().Trim();
                    int    ID = 0;
                    Int32.TryParse(i, out ID);

                    Salecounter++;
                    string   d = item["Date"].ToString().Trim();
                    DateTime Date;
                    DateTime.TryParse(d, out Date);

                    string u      = item["UserID"].ToString().Trim();
                    int    UserID = 0;
                    Int32.TryParse(u, out UserID);

                    string f    = item["Flag"].ToString().Trim();
                    int    Flag = 0;
                    Int32.TryParse(f, out Flag);


                    string Remarks = item["Remarks"].ToString().Trim();

                    string  r     = item["Total"].ToString().Trim();
                    decimal Total = 0;
                    Decimal.TryParse(r, out Total);



                    string  dis      = item["Discount"].ToString().Trim();
                    decimal Discount = 0;
                    Decimal.TryParse(dis, out Discount);

                    int BranchID = 1;



                    if (Flag == 1)
                    {
                        saleInvoice          = db.SaleInvoices.Create();
                        saleInvoice.BranchID = BranchID;
                        saleInvoice.Date     = Date;
                        saleInvoice.Discount = Discount;
                        saleInvoice.Flag     = 9;
                        saleInvoice.Remarks  = "Reda1" + ID;
                        saleInvoice.Total    = Total;
                        saleInvoice.UserID   = UserID;
                        db.SaleInvoices.Add(saleInvoice);

                        var resultsDetails = from myRow in dtDetails.AsEnumerable()
                                             where myRow.Field <string>("SaleInvoiceID") == i
                                             select myRow;

                        DataAccess.SaleInvoiceDetail child;// = db.SaleInvoiceDetails.Create();
                        foreach (var details in resultsDetails)
                        {
                            child = db.SaleInvoiceDetails.Create();
                            Detailscounter++;

                            string it     = details["ItemID"].ToString().Trim();
                            int    ItemID = 0;
                            Int32.TryParse(it, out ItemID);

                            string inv         = details["InventoryID"].ToString().Trim();
                            int    InventoryID = 0;
                            Int32.TryParse(inv, out InventoryID);

                            string q         = details["Quanitity"].ToString().Trim();
                            int    Quanitity = 0;
                            Int32.TryParse(q, out Quanitity);

                            string  un        = details["UnitPrice"].ToString().Trim();
                            decimal UnitPrice = 0;
                            Decimal.TryParse(un, out UnitPrice);

                            child.CurrentQuanitity = 0;
                            child.InventoryID      = InventoryID;
                            child.ItemID           = ItemID;
                            child.PurchaseQuantity = 0;
                            child.Quanitity        = Quanitity;
                            child.Remarks          = i;
                            child.UnitPrice        = UnitPrice;
                            saleInvoice.SaleInvoiceDetails.Add(child);

                            inventory = db.Inventories.Where(s => s.ID == child.InventoryID).SingleOrDefault();
                            inventory.CurrentQuanity -= child.Quanitity;
                        }
                        int savedRow = db.SaveChanges();
                        if (savedRow > 0)
                        {
                        }
                    }
                }
                MessageBox.Show(Salecounter.ToString() + "  row inserted", " Details: " + Detailscounter);
            }
            catch (Exception ex)
            {
                ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null);
            }
        }
示例#8
0
 private void bindingSource1_AddingNew(object sender, AddingNewEventArgs e)
 {
     DataAccess.SaleInvoice obj = (DataAccess.SaleInvoice)e.NewObject;
     //obj.Flag = 0;//New Invoice
 }