Ejemplo n.º 1
0
        private void SaveCollection()
        {
            DataClasses1DataContext db = new DataClasses1DataContext();

            using (var scope = new System.Transactions.TransactionScope())
            {
                foreach (DataGridViewRow row in dataGridView3.Rows)
                {
                    Edison_DispatchPayment AddItems1 = new Edison_DispatchPayment();
                    AddItems1.Date       = dateTimePicker1.Value;
                    AddItems1.CustID     = Convert.ToInt32(row.Cells[1].Value.ToString() == "" ? "0" : row.Cells[1].Value.ToString());
                    AddItems1.Amount     = Convert.ToDecimal(row.Cells[5].Value.ToString() == "" ? "0" : row.Cells[5].Value.ToString());
                    AddItems1.DispatchNo = Convert.ToInt32(textBox4.Text);
                    db.Edison_DispatchPayments.InsertOnSubmit(AddItems1);
                    db.SubmitChanges();
                }



                scope.Complete();
            }

            INV_RevertState();
            Inv_DisableAll();

            db.Dispose();

            form1.RefreshForm();
        }
Ejemplo n.º 2
0
        private void Invoice_SaveAll()
        {
            try
            {
                DataClasses1DataContext db = new DataClasses1DataContext();


                var validation = from s in db.Edison_InvoiceHDRs
                                 where s.DispatchNo.Equals(textBox2.Text) && s.CustID.Equals(InvCustomerList.EditValue)
                                 select s;

                if (validation.Any())
                {
                    MessageBox.Show("You cannot Make Another Bill Of the Same Customer, Please Check!!");
                    return;
                }


                using (var scope = new System.Transactions.TransactionScope())
                {
                    Edison_InvoiceHDR objCourse = new Edison_InvoiceHDR();

                    objCourse.Date = InvDate.Value.Date;

                    objCourse.DispatchNo = Convert.ToInt32(textBox2.Text);

                    objCourse.CustID = Convert.ToInt32(InvCustomerList.EditValue);


                    objCourse.TotalAmount = Convert.ToDecimal(txtInvoicingAmount.Text == "" ? "0" : txtInvoicingAmount.Text);

                    objCourse.DiscountAmount     = Convert.ToDecimal(textBox3.Text == "" ? "0" : textBox3.Text);
                    objCourse.DiscountPercentage = Convert.ToDecimal(textBox4.Text == "" ? "0" : textBox4.Text);
                    objCourse.NetAmount          = Convert.ToDecimal(textBox5.Text == "" ? "0" : textBox5.Text);
                    objCourse.PrevBalance        = Convert.ToDecimal(textBox8.Text == "" ? "0" : textBox8.Text);
                    objCourse.GrandTotal         = Convert.ToDecimal(textBox7.Text == "" ? "0" : textBox7.Text);

                    db.Edison_InvoiceHDRs.InsertOnSubmit(objCourse);
                    db.SubmitChanges();

                    textBox9.Text = objCourse.InvoiceID.ToString();

                    //dataGridView4.Sort(dataGridView1.Columns[1], ListSortDirection.Ascending);
                    //this.dataGridView4.Columns[1].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;


                    int i = 1;

                    foreach (DataGridViewRow row in dataGridView4.Rows)
                    {
                        Edison_InvoiceDTL AddItems = new Edison_InvoiceDTL();

                        AddItems.PID         = Convert.ToInt32(row.Cells[1].Value.ToString() == "" ? "0" : row.Cells[1].Value.ToString());
                        AddItems.Qty         = Convert.ToInt32(row.Cells[3].Value.ToString() == "" ? "0" : row.Cells[3].Value.ToString());
                        AddItems.Rate        = Convert.ToDecimal(row.Cells[4].Value.ToString() == "" ? "0" : row.Cells[4].Value.ToString());
                        AddItems.TotalAmount = Convert.ToDecimal(row.Cells[5].Value.ToString() == "" ? "0" : row.Cells[5].Value.ToString());
                        AddItems.DispatchNo  = Convert.ToInt32(textBox2.Text);


                        var getTheSelecteddata = from s in db.Edison_Products
                                                 where s.ProductID.Equals(AddItems.PID)
                                                 select s;

                        if (getTheSelecteddata.Any())
                        {
                            foreach (var ab in getTheSelecteddata)
                            {
                                AddItems.OriginalRetailSaleRate = ab.RSSalePrice;
                                AddItems.OriginalWholeSaleRate  = ab.WSSalePrice;
                                AddItems.OriginalPurchRate      = ab.PurchasePrice;

                                break;
                            }
                        }
                        else
                        {
                            AddItems.OriginalRetailSaleRate = 0;
                            AddItems.OriginalWholeSaleRate  = 0;
                            AddItems.OriginalPurchRate      = 0;
                        }

                        AddItems.InvoiceID = Convert.ToInt32(textBox9.Text);
                        db.Edison_InvoiceDTLs.InsertOnSubmit(AddItems);
                        db.SubmitChanges();
                    }

                    scope.Complete();
                    INV_RevertState();
                    Inv_DisableAll();
                }

                form1.RefreshForm();
            }
            catch (Exception err)
            {
                MessageBox.Show("Error on Save " + err);
            }
        }