Exemple #1
0
        private bool SaveThisSale()
        {
            string titleBackUp = this.Text;

            this.Text = "Saving....";
            int transactionIdBackUp = transaction.ID;//need this in case of rollback

            //try
            //{
            comm.BeginBatchOperation();
            SalePurchase sale;
            Item         item;
            Unit         unit;

            transaction.TransactionTime = DateTime.Parse(estimateDatePicker.Value.ToShortDateString() + " "
                                                         + DateTime.Now.TimeOfDay.ToString());
            transaction.ParentProject.Name = projectSelector.Text;
            transaction = tm.SyncTransaction(transaction);
            sales       = new List <SalePurchase>();
            foreach (DataGridViewRow row in purchaseGrid.Rows)
            {
                if (!row.IsNewRow)
                {
                    unit             = new Unit();
                    unit.Name        = (string)row.Cells[4].Value;
                    item             = new Item((string)row.Cells[1].Value, double.Parse(row.Cells[3].Value.ToString()), unit);
                    sale             = new SalePurchase();
                    sale.Number      = (int)row.Cells[0].Value;
                    sale.ID          = (int)row.Cells["id"].Value;
                    sale.Quantity    = double.Parse(row.Cells[2].Value.ToString());
                    sale.SaleRate    = double.Parse(row.Cells[3].Value.ToString());
                    sale.Item        = item;
                    sale.SaleUnit    = unit;
                    sale.Transaction = transaction;
                    sales.Add(sale);
                }
            }
            //create payment
            payment             = new Payment();
            payment.Amount      = double.Parse(currentPayment.Text);
            payment.BankMoney   = eMoney.Checked;
            payment.Transaction = transaction;
            if (!paymentMode)
            {
                sm.SyncSales(sales, updateItems.Checked, transaction.ID, true);
            }
            pm.SyncPayment(payment, estimateDatePicker.Value);
            comm.ConfirmBatchOperation();
            return(true);
            //}
            //catch (Exception ex)
            //{
            //    cancelFormClose = true;
            //    comm.RollBackBatchOperation();
            //    transaction.ID = transactionIdBackUp;
            //    MessageBox.Show("Please try again." + Environment.NewLine + "Details:" + ex.Message, "Sorry! Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return false;
            //}
            //finally
            //{
            //    this.Text = titleBackUp;
            //    titleBackUp = string.Empty;
            //}
        }