Example #1
0
        public List<InvoiceHeaderBO> GetAllInvoicesForCurrentDate()
        {
            DBEgine objDbAccess = new DBEgine();
            var list = new List<InvoiceHeaderBO>();
            try
            {

                objDbAccess.DBOpen();

                SqlDataReader dr = objDbAccess.ExecuteReader("Sales.GetCurrentDayInvoices", null);

                while (dr.Read())
                {
                    var invoice = new InvoiceHeaderBO();

                    invoice.InvoiceID = int.Parse(dr["InvoiceID"].ToString());
                    invoice.InvoiceNumber = dr["InvoiceNumber"].ToString();

                    list.Add(invoice);
                }

                return list;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objDbAccess.DBClose();
            }
        }
Example #2
0
        public bool DeleteInvoice(InvoiceHeaderBO invoiceHeader)
        {
            DBEgine objDbAccess = new DBEgine();
            bool result = false;
            SqlTransaction tran = null;
            try
            {
                SqlParameter[] parms = new SqlParameter[1];

                SqlParameter parmInvoiceID = new SqlParameter();
                parmInvoiceID.Value = invoiceHeader.InvoiceID;
                parmInvoiceID.SqlDbType = SqlDbType.Int;
                parmInvoiceID.Direction = ParameterDirection.Input;
                parmInvoiceID.ParameterName = "@InvoiceID";
                parms[0] = parmInvoiceID;

                objDbAccess.DBOpen(tran);

                if (objDbAccess.ExecNonQueryStoredProc("Sales.DeleteInvoices", parms) > 0)
                {
                    result = true;
                }

                objDbAccess.DBTransAction.Commit();
                return result;

            }
            catch
            {
                objDbAccess.DBTransAction.Rollback();
                throw;
            }
            finally
            {
                objDbAccess.DBClose();
            }
        }
Example #3
0
        public bool SaveInvoice(InvoiceHeaderBO invoiceHeader, List<InvoiceDetailBO> invoiceDetail,ref string invoiceNumber,ref int invoiceID)
        {
            DBEgine objDbAccess = new DBEgine();
            bool result = false;
            SqlTransaction tran = null;
            try
            {
                SqlParameter[] parms = new SqlParameter[8];

                SqlParameter parmInvoiceID = new SqlParameter();
                parmInvoiceID.Value = invoiceHeader.InvoiceID;
                parmInvoiceID.SqlDbType = SqlDbType.Int;
                parmInvoiceID.Direction = ParameterDirection.InputOutput;
                parmInvoiceID.ParameterName = "@InvoiceID";
                parms[0] = parmInvoiceID;

                SqlParameter parmInvoiceNumber = new SqlParameter();
                parmInvoiceNumber.Value = invoiceHeader.InvoiceNumber;
                parmInvoiceNumber.SqlDbType = SqlDbType.VarChar;
                parmInvoiceNumber.Direction = ParameterDirection.InputOutput;
                parmInvoiceNumber.ParameterName = "@InvoiceNumber";
                parms[1] = parmInvoiceNumber;

                SqlParameter parmIsInvalied = new SqlParameter();
                parmIsInvalied.Value = invoiceHeader.StatusID;
                parmIsInvalied.SqlDbType = SqlDbType.Int;
                parmIsInvalied.Direction = ParameterDirection.Input;
                parmIsInvalied.ParameterName = "@StatusID";
                parms[2] = parmIsInvalied;

                SqlParameter parmTotal = new SqlParameter();
                parmTotal.Value = invoiceHeader.Total;
                parmTotal.SqlDbType = SqlDbType.Decimal;
                parmTotal.Direction = ParameterDirection.Input;
                parmTotal.ParameterName = "@Total";
                parms[3] = parmTotal;

                SqlParameter parmCreatedUser = new SqlParameter();
                parmCreatedUser.Value = invoiceHeader.CreatedUser;
                parmCreatedUser.SqlDbType = SqlDbType.Int;
                parmCreatedUser.Direction = ParameterDirection.Input;
                parmCreatedUser.ParameterName = "@CreatedUser";
                parms[4] = parmCreatedUser;

                SqlParameter parmCustomerID = new SqlParameter();
                parmCustomerID.Value = invoiceHeader.CustomerID;
                parmCustomerID.SqlDbType = SqlDbType.Int;
                parmCustomerID.Direction = ParameterDirection.Input;
                parmCustomerID.ParameterName = "@CustomerID";
                parms[5] = parmCustomerID;

                SqlParameter parmReceivedAmount = new SqlParameter();
                parmReceivedAmount.Value = invoiceHeader.ReceivedAmount;
                parmReceivedAmount.SqlDbType = SqlDbType.Decimal;
                parmReceivedAmount.Direction = ParameterDirection.Input;
                parmReceivedAmount.ParameterName = "@ReceivedAmount";
                parms[6] = parmReceivedAmount;

                SqlParameter parmBalance = new SqlParameter();
                parmBalance.Value = invoiceHeader.Balance;
                parmBalance.SqlDbType = SqlDbType.Int;
                parmBalance.Direction = ParameterDirection.Input;
                parmBalance.ParameterName = "@Balance";
                parms[7] = parmBalance;

                objDbAccess.DBOpen(tran);

                if (objDbAccess.ExecNonQueryStoredProc("Sales.SaveInvoice", parms) > 0)
                {
                    foreach (InvoiceDetailBO obj in invoiceDetail)
                    {
                        obj.InvoiceId = int.Parse(parms[0].Value.ToString());
                        bool success = SaveInvoiceDetail(objDbAccess, obj);
                        if (!success)
                        {
                            objDbAccess.DBTransAction.Rollback();
                            return false;
                        }
                    }
                    invoiceNumber = parms[1].Value.ToString();
                    invoiceID = int.Parse(parms[0].Value.ToString());
                    result = true;
                }

                objDbAccess.DBTransAction.Commit();
                return result;

            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objDbAccess.DBClose();
            }
        }
Example #4
0
        private void SaveInvoice(decimal balance)
        {
            try
            {
                if (InvoiceID > 0 && !ScreenFunctions.Update)
                {
                    MessageBoxClass.ShowMessage(CommonMethods.GetError("INV_020"), false);
                    return;
                }
                if (InvoiceID == -1 || InvoiceDetailBOList != null)
                {
                    var invoiceHeaderBO = new InvoiceHeaderBO();

                    string invoiceNumber = string.Empty;
                    if (textBoxInvoiceNumber.Text == "New")
                    {
                        invoiceNumber="INV00000000000000";
                    }
                    else
                    {
                        invoiceNumber = textBoxInvoiceNumber.Text.Trim();
                    }
                    invoiceHeaderBO.InvoiceID = InvoiceID;
                    invoiceHeaderBO.InvoiceNumber = invoiceNumber;
                    invoiceHeaderBO.CustomerID = 1;
                    invoiceHeaderBO.ReceivedAmount = numericUpDownAmount.Value;
                    invoiceHeaderBO.Balance = balance;
                    invoiceHeaderBO.StatusID = (int)CommonEnums.InvoiceStatus.Saved;
                    invoiceHeaderBO.CreatedUser = Common.User.UserId;
                    invoiceHeaderBO.Total = 0;

                    int invID = -1;
                    bool result = new InvoiceDAL().SaveInvoice(invoiceHeaderBO, InvoiceDetailBOList, ref invoiceNumber, ref invID);

                    InvoiceID = invID;

                    if (result)
                    {
                        textBoxInvoiceNumber.Text = invoiceNumber;
                        MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_001"), false);
                        PrintReceipt();
                        ChangeStatus();
                    }
                    else
                    {
                        MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_002"), false);
                    }
                }
                else
                {
                    MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_007"), false);
                }
            }
            catch (SqlException ex)
            {
                MessageBoxClass.ShowMessage(ex.Message, true);
            }
            catch
            {
                MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_002"), true);
            }
        }
Example #5
0
        private void ChangeStatus()
        {
            try
            {
                var invoiceHeaderBO = new InvoiceHeaderBO();
                invoiceHeaderBO.InvoiceID = InvoiceID;
                invoiceHeaderBO.InvoiceNumber = textBoxInvoiceNumber.Text.Trim();
                invoiceHeaderBO.CustomerID = 1;
                invoiceHeaderBO.StatusID = (int)CommonEnums.InvoiceStatus.Printed;
                invoiceHeaderBO.CreatedUser = Common.User.UserId;
                invoiceHeaderBO.Total = 0;

                new InvoiceDAL().SaveInvoiceStatus(invoiceHeaderBO);
            }
            catch
            {
                MessageBoxClass.ShowMessage(CommonMethods.GetError("U_007"), true);
            }
        }
Example #6
0
        private void buttonRefund_Click(object sender, EventArgs e)
        {
            try
            {
                if ((int)CommonEnums.InvoiceStatus.Refunded != InvoiceStatusID)
                {
                    var invoiceHeaderBO = new InvoiceHeaderBO();

                    invoiceHeaderBO.InvoiceID = InvoiceID;
                    invoiceHeaderBO.InvoiceNumber = textBoxInvoiceNumber.Text.Trim();
                    invoiceHeaderBO.CustomerID = 1;
                    invoiceHeaderBO.StatusID = (int)CommonEnums.InvoiceStatus.Refunded;
                    invoiceHeaderBO.CreatedUser = Common.User.UserId;
                    invoiceHeaderBO.Total = 0;

                    bool result = new InvoiceDAL().SaveInvoiceStatus(invoiceHeaderBO);

                    if (result)
                    {
                        MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_005"), false);
                        IsRefunded = true;
                        PrintReceipt();
                        IsRefunded = false;
                        buttonNew_Click(null, null);
                    }
                    else
                    {
                        MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_006"), false);
                    }
                }
                else
                {
                    MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_009"), false);
                }

            }
            catch
            {
                MessageBoxClass.ShowMessage(CommonMethods.GetError("SAL_006"), true);
            }
        }