public DataSet GetInvoicesBalance()
        {
            DataSet ds = new DataSet();
            SalesInvoiceHeaderData sihd = new SalesInvoiceHeaderData();

            try
            {
                ds = sihd.GetInovoicesBalanceDataSet();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                sihd = null;
            }
            return(ds);
        }
        public DataSet GetSalesInvoiceHeadersDataSet(string where, string orderBy)
        {
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();
            DataSet ds = new DataSet();

            try
            {
                ds = data.GetAllSalesInvoiceHeadersDynamicDataSet(where, orderBy);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "GetSalesInvoiceHeadersDataSet");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(ds);
        }
        public SalesInvoiceHeaderCollection GetSalesInvoiceHeadersCollection(string where, string orderBy)
        {
            SalesInvoiceHeaderData       data = new SalesInvoiceHeaderData();
            SalesInvoiceHeaderCollection col  = new SalesInvoiceHeaderCollection();

            try
            {
                col = data.GetAllSalesInvoiceHeadersDynamicCollection(where, orderBy);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "GetSalesInvoiceHeadersCollection");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(col);
        }
        public SalesInvoiceHeader GetSalesInvoiceHeaders(int invoiceID)
        {
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();
            SalesInvoiceHeader     sih  = new SalesInvoiceHeader();

            try
            {
                sih = data.GetSalesInvoiceHeader(invoiceID);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "GetSalesInvoiceHeaders");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(sih);
        }
        public bool UpdateSalesInvoiceHeader(SalesInvoiceHeader salesinvoiceheader)
        {
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();
            bool ret = false;

            try
            {
                ret = data.UpdateSalesInvoiceHeader(salesinvoiceheader);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "UpdateSalesInvoiceHeader");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(ret);
        }
        public bool RemoveSalesInvoiceHeader(int invoiceID)
        {
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();
            bool ret = false;

            try
            {
                ret = data.DeleteSalesInvoiceHeader(invoiceID);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "RemoveSalesInvoiceHeader");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(ret);
        }
        public bool InvoiceExist(int SalesOrderId)
        {
            bool ret = false;
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();

            try
            {
                ret = data.InvoiceExist(SalesOrderId);
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(ret);
        }
        public int AddSalesInvoiceHeader(SalesInvoiceHeader salesinvoiceheader)
        {
            SalesInvoiceHeaderData data = new SalesInvoiceHeaderData();
            int id = 0;

            try
            {
                if (!InvoiceExist(salesinvoiceheader.SaleOrderID))
                {
                    id = data.AddSalesInvoiceHeader(salesinvoiceheader);
                }
            }
            catch (Exception ex)
            {
                log.Write(ex.Message, "AddSalesInvoiceHeader");
                throw (ex);
            }
            finally
            {
                data = null;
            }
            return(id);
        }