/// <summary>
        /// Function to get particular values from PurchaseMaster table based on the parameter
        /// </summary>
        /// <param name="purchaseMasterId"></param>
        /// <returns></returns>
        public PurchaseMasterInfo PurchaseMasterView(Decimal purchaseMasterId)
        {
            PurchaseMasterInfo purchasemasterinfo = new PurchaseMasterInfo();
               PurchaseMasterSP SPPurchaseMaster = new PurchaseMasterSP();

               try
               {
               purchasemasterinfo = SPPurchaseMaster.PurchaseMasterView(purchaseMasterId);
               }
               catch (Exception ex)
               {
               MessageBox.Show("PIBll 15:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);

               }
               return purchasemasterinfo;
        }
        public decimal PurchaseMasterVoucherMax(decimal decVoucherTypeId)
        {
            PurchaseMasterInfo purchasemasterinfo = new PurchaseMasterInfo();
               PurchaseMasterSP SPPurchaseMaster = new PurchaseMasterSP();
               decimal decVoucherNoMax = 0;
               try
               {
               decVoucherNoMax = SPPurchaseMaster.PurchaseMasterVoucherMax(decVoucherTypeId);
               }
               catch (Exception ex)
               {
               MessageBox.Show("PIBll 17:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);

               }
               return decVoucherNoMax;
        }
        public void PurchaseMasterEdit(PurchaseMasterInfo purchasemasterinfo)
        {
            PurchaseMasterSP SPPurchaseMaster = new PurchaseMasterSP();

               try
               {
                SPPurchaseMaster.PurchaseMasterEdit(purchasemasterinfo);
               }
               catch (Exception ex)
               {
               MessageBox.Show("PIBll 22:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);

               }
        }
        public decimal PurchaseMasterAdd(PurchaseMasterInfo purchasemasterinfo)
        {
            PurchaseMasterSP SPPurchaseMaster = new PurchaseMasterSP();
               decimal decPurchaseMasterId = 0;
               try
               {
               decPurchaseMasterId = SPPurchaseMaster.PurchaseMasterAdd(purchasemasterinfo);
               }
               catch (Exception ex)
               {
               MessageBox.Show("PIBll 21:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);

               }
               return decPurchaseMasterId;
        }
 public decimal PurchaseOrderDetailsDelete(decimal decVoucherTypeId)
 {
     PurchaseMasterInfo purchasemasterinfo = new PurchaseMasterInfo();
     PurchaseOrderDetailsSP SPPurchaseOrderDetails = new PurchaseOrderDetailsSP();
     decimal decResult = 0;
     try
     {
         decResult = SPPurchaseOrderDetails.PurchaseOrderDetailsDelete(decVoucherTypeId);
     }
     catch (Exception ex)
     {
         MessageBox.Show("PoBll 4:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return decResult;
 }
 /// <summary>
 /// Function to get particular values from PurchaseMaster table based on the parameter
 /// </summary>
 /// <param name="purchaseMasterId"></param>
 /// <returns></returns>
 public PurchaseMasterInfo PurchaseMasterView(Decimal purchaseMasterId)
 {
     PurchaseMasterInfo purchasemasterinfo = new PurchaseMasterInfo();
     SqlDataReader sdrreader = null;
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PurchaseMasterView", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@purchaseMasterId", SqlDbType.Decimal);
         sprmparam.Value = purchaseMasterId;
         sdrreader = sccmd.ExecuteReader();
         while (sdrreader.Read())
         {
             purchasemasterinfo.PurchaseMasterId = decimal.Parse(sdrreader[0].ToString());
             purchasemasterinfo.VoucherNo = sdrreader[1].ToString();
             purchasemasterinfo.InvoiceNo = sdrreader[2].ToString();
             purchasemasterinfo.SuffixPrefixId = decimal.Parse(sdrreader[3].ToString());
             purchasemasterinfo.VoucherTypeId = decimal.Parse(sdrreader[4].ToString());
             purchasemasterinfo.Date = DateTime.Parse(sdrreader[5].ToString());
             purchasemasterinfo.LedgerId = decimal.Parse(sdrreader[6].ToString());
             purchasemasterinfo.VendorInvoiceNo = sdrreader[7].ToString();
             purchasemasterinfo.VendorInvoiceDate = DateTime.Parse(sdrreader[8].ToString());
             purchasemasterinfo.CreditPeriod = sdrreader[9].ToString();
             purchasemasterinfo.ExchangeRateId = decimal.Parse(sdrreader[10].ToString());
             purchasemasterinfo.Narration = sdrreader[11].ToString();
             purchasemasterinfo.PurchaseAccount = decimal.Parse(sdrreader[12].ToString());
             purchasemasterinfo.PurchaseOrderMasterId = decimal.Parse(sdrreader[13].ToString());
             purchasemasterinfo.MaterialReceiptMasterId = decimal.Parse(sdrreader[14].ToString());
             purchasemasterinfo.AdditionalCost = decimal.Parse(sdrreader[15].ToString());
             purchasemasterinfo.TotalTax = decimal.Parse(sdrreader[16].ToString());
             purchasemasterinfo.BillDiscount = decimal.Parse(sdrreader[17].ToString());
             purchasemasterinfo.GrandTotal = decimal.Parse(sdrreader[18].ToString());
             purchasemasterinfo.TotalAmount = decimal.Parse(sdrreader[19].ToString());
             purchasemasterinfo.UserId = decimal.Parse(sdrreader[20].ToString());
             purchasemasterinfo.LrNo = sdrreader[21].ToString();
             purchasemasterinfo.TransportationCompany = sdrreader[22].ToString();
             purchasemasterinfo.FinancialYearId = decimal.Parse(sdrreader[23].ToString());
             purchasemasterinfo.ExtraDate = DateTime.Parse(sdrreader[24].ToString());
             purchasemasterinfo.Extra1 = sdrreader[25].ToString();
             purchasemasterinfo.Extra2 = sdrreader[26].ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sdrreader.Close();
         sqlcon.Close();
     }
     return purchasemasterinfo;
 }
 /// <summary>
 /// Function to Update values in PurchaseMaster Table
 /// </summary>
 /// <param name="purchasemasterinfo"></param>
 public void PurchaseMasterEdit(PurchaseMasterInfo purchasemasterinfo)
 {
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PurchaseMasterEdit", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@purchaseMasterId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.PurchaseMasterId;
         sprmparam = sccmd.Parameters.Add("@voucherNo", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.VoucherNo;
         sprmparam = sccmd.Parameters.Add("@invoiceNo", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.InvoiceNo;
         sprmparam = sccmd.Parameters.Add("@suffixPrefixId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.SuffixPrefixId;
         sprmparam = sccmd.Parameters.Add("@voucherTypeId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.VoucherTypeId;
         sprmparam = sccmd.Parameters.Add("@date", SqlDbType.DateTime);
         sprmparam.Value = purchasemasterinfo.Date;
         sprmparam = sccmd.Parameters.Add("@ledgerId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.LedgerId;
         sprmparam = sccmd.Parameters.Add("@vendorInvoiceNo", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.VendorInvoiceNo;
         sprmparam = sccmd.Parameters.Add("@vendorInvoiceDate", SqlDbType.DateTime);
         sprmparam.Value = purchasemasterinfo.VendorInvoiceDate;
         sprmparam = sccmd.Parameters.Add("@creditPeriod", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.CreditPeriod;
         sprmparam = sccmd.Parameters.Add("@exchangeRateId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.ExchangeRateId;
         sprmparam = sccmd.Parameters.Add("@narration", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.Narration;
         sprmparam = sccmd.Parameters.Add("@purchaseAccount", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.PurchaseAccount;
         sprmparam = sccmd.Parameters.Add("@purchaseOrderMasterId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.PurchaseOrderMasterId;
         sprmparam = sccmd.Parameters.Add("@materialReceiptMasterId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.MaterialReceiptMasterId;
         sprmparam = sccmd.Parameters.Add("@additionalCost", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.AdditionalCost;
         sprmparam = sccmd.Parameters.Add("@totalTax", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.TotalTax;
         sprmparam = sccmd.Parameters.Add("@billDiscount", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.BillDiscount;
         sprmparam = sccmd.Parameters.Add("@grandTotal", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.GrandTotal;
         sprmparam = sccmd.Parameters.Add("@totalAmount", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.TotalAmount;
         sprmparam = sccmd.Parameters.Add("@userId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.UserId;
         sprmparam = sccmd.Parameters.Add("@lrNo", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.LrNo;
         sprmparam = sccmd.Parameters.Add("@transportationCompany", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.TransportationCompany;
         sprmparam = sccmd.Parameters.Add("@financialYearId", SqlDbType.Decimal);
         sprmparam.Value = purchasemasterinfo.FinancialYearId;
         sprmparam = sccmd.Parameters.Add("@extraDate", SqlDbType.DateTime);
         sprmparam.Value = purchasemasterinfo.ExtraDate;
         sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.Extra1;
         sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
         sprmparam.Value = purchasemasterinfo.Extra2;
         sccmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
 }