/// <summary>
 /// Function to Update values in PhysicalStockDetails Table
 /// </summary>
 /// <param name="physicalstockdetailsinfo"></param>
 public void PhysicalStockDetailsEdit(PhysicalStockDetailsInfo physicalstockdetailsinfo)
 {
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PhysicalStockDetailsEdit", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@physicalStockDetailsId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.PhysicalStockDetailsId;
         sprmparam = sccmd.Parameters.Add("@physicalStockMasterId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.PhysicalStockMasterId;
         sprmparam = sccmd.Parameters.Add("@productId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.ProductId;
         sprmparam = sccmd.Parameters.Add("@qty", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Qty;
         sprmparam = sccmd.Parameters.Add("@rate", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Rate;
         sprmparam = sccmd.Parameters.Add("@unitId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.UnitId;
         sprmparam = sccmd.Parameters.Add("@unitConversionId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.UnitConversionId;
         sprmparam = sccmd.Parameters.Add("@batchId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.BatchId;
         sprmparam = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.GodownId;
         sprmparam = sccmd.Parameters.Add("@rackId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.RackId;
         sprmparam = sccmd.Parameters.Add("@amount", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Amount;
         sprmparam = sccmd.Parameters.Add("@slno", SqlDbType.Int);
         sprmparam.Value = physicalstockdetailsinfo.Slno;
         sprmparam = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
         sprmparam.Value = physicalstockdetailsinfo.Extra1;
         sprmparam = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
         sprmparam.Value = physicalstockdetailsinfo.Extra2;
         sccmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
 }
 /// <summary>
 /// Function to Update values in PhysicalStockDetails Table
 /// </summary>
 /// <param name="physicalstockdetailsinfo"></param>
 public void PhysicalStockDetailsEdit(PhysicalStockDetailsInfo physicalstockdetailsinfo)
 {
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PhysicalStockDetailsEdit", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam       = sccmd.Parameters.Add("@physicalStockDetailsId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.PhysicalStockDetailsId;
         sprmparam       = sccmd.Parameters.Add("@physicalStockMasterId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.PhysicalStockMasterId;
         sprmparam       = sccmd.Parameters.Add("@productId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.ProductId;
         sprmparam       = sccmd.Parameters.Add("@qty", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Qty;
         sprmparam       = sccmd.Parameters.Add("@rate", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Rate;
         sprmparam       = sccmd.Parameters.Add("@unitId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.UnitId;
         sprmparam       = sccmd.Parameters.Add("@unitConversionId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.UnitConversionId;
         sprmparam       = sccmd.Parameters.Add("@batchId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.BatchId;
         sprmparam       = sccmd.Parameters.Add("@godownId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.GodownId;
         sprmparam       = sccmd.Parameters.Add("@rackId", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.RackId;
         sprmparam       = sccmd.Parameters.Add("@amount", SqlDbType.Decimal);
         sprmparam.Value = physicalstockdetailsinfo.Amount;
         sprmparam       = sccmd.Parameters.Add("@slno", SqlDbType.Int);
         sprmparam.Value = physicalstockdetailsinfo.Slno;
         sprmparam       = sccmd.Parameters.Add("@extra1", SqlDbType.VarChar);
         sprmparam.Value = physicalstockdetailsinfo.Extra1;
         sprmparam       = sccmd.Parameters.Add("@extra2", SqlDbType.VarChar);
         sprmparam.Value = physicalstockdetailsinfo.Extra2;
         sccmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sqlcon.Close();
     }
 }
        /// <summary>
        /// Function to get particular values from PhysicalStockDetails table based on the parameter
        /// </summary>
        /// <param name="physicalStockDetailsId"></param>
        /// <returns></returns>
        public PhysicalStockDetailsInfo PhysicalStockDetailsView(decimal physicalStockDetailsId)
        {
            PhysicalStockDetailsInfo physicalstockdetailsinfo = new PhysicalStockDetailsInfo();
            SqlDataReader            sdrreader = null;

            try
            {
                if (sqlcon.State == ConnectionState.Closed)
                {
                    sqlcon.Open();
                }
                SqlCommand sccmd = new SqlCommand("PhysicalStockDetailsView", sqlcon);
                sccmd.CommandType = CommandType.StoredProcedure;
                SqlParameter sprmparam = new SqlParameter();
                sprmparam       = sccmd.Parameters.Add("@physicalStockDetailsId", SqlDbType.Decimal);
                sprmparam.Value = physicalStockDetailsId;
                sdrreader       = sccmd.ExecuteReader();
                while (sdrreader.Read())
                {
                    physicalstockdetailsinfo.PhysicalStockDetailsId = decimal.Parse(sdrreader[0].ToString());
                    physicalstockdetailsinfo.PhysicalStockMasterId  = decimal.Parse(sdrreader[1].ToString());
                    physicalstockdetailsinfo.ProductId        = decimal.Parse(sdrreader[2].ToString());
                    physicalstockdetailsinfo.Qty              = decimal.Parse(sdrreader[3].ToString());
                    physicalstockdetailsinfo.Rate             = decimal.Parse(sdrreader[4].ToString());
                    physicalstockdetailsinfo.UnitId           = decimal.Parse(sdrreader[5].ToString());
                    physicalstockdetailsinfo.UnitConversionId = decimal.Parse(sdrreader[6].ToString());
                    physicalstockdetailsinfo.BatchId          = decimal.Parse(sdrreader[7].ToString());
                    physicalstockdetailsinfo.GodownId         = decimal.Parse(sdrreader[8].ToString());
                    physicalstockdetailsinfo.RackId           = decimal.Parse(sdrreader[9].ToString());
                    physicalstockdetailsinfo.Amount           = decimal.Parse(sdrreader[10].ToString());
                    physicalstockdetailsinfo.Slno             = int.Parse(sdrreader[11].ToString());
                    physicalstockdetailsinfo.ExtraDate        = DateTime.Parse(sdrreader[12].ToString());
                    physicalstockdetailsinfo.Extra1           = sdrreader[13].ToString();
                    physicalstockdetailsinfo.Extra2           = sdrreader[14].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sdrreader.Close();
                sqlcon.Close();
            }
            return(physicalstockdetailsinfo);
        }
 /// <summary>
 /// Adding PhysicalStockDetails when updating
 /// </summary>
 public void EditPhysicalStockDetails()
 {
     try
     {
         ProductInfo infoProduct = new ProductInfo();
         ProductSP spProduct = new ProductSP();
         PhysicalStockDetailsInfo infoPhysicalStockDetails = new PhysicalStockDetailsInfo();
         PhysicalStockDetailsSP spPhysicalStockDetails = new PhysicalStockDetailsSP();
         int inRowcount = dgvPhysicalStock.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             infoPhysicalStockDetails.PhysicalStockMasterId = decMasterId;
             infoPhysicalStockDetails.PhysicalStockDetailsId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtPhysicalStockDetailId"].Value);
             if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 infoProduct = spProduct.ProductViewByCode(dgvPhysicalStock.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                 infoPhysicalStockDetails.ProductId = infoProduct.ProductId;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.GodownId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbGodown"].Value.ToString());
             }
             else
             {
                 infoPhysicalStockDetails.GodownId = 0;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.RackId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbRack"].Value.ToString());
             }
             else
             {
                 infoPhysicalStockDetails.RackId = 0;
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.BatchId = Convert.ToDecimal(Convert.ToString(dgvPhysicalStock.Rows[inI].Cells["dgvcmbBatch"].Value));
             }
             else
             {
                 infoPhysicalStockDetails.BatchId = 0;
             }
             if (dgvPhysicalStock.Rows[0].Cells["dgvcmbBatch"].Value == null && dgvPhysicalStock.Rows[0].Cells["dgvcmbBatch"].Value == null)
             {
                 MessageBox.Show("Can't update physical stock without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 dgvPhysicalStock.ClearSelection();
                 dgvPhysicalStock.Focus();
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.Qty = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             }
             if (dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
             {
                 infoPhysicalStockDetails.UnitId = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
             }
             infoPhysicalStockDetails.Rate = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoPhysicalStockDetails.Amount = Convert.ToDecimal(dgvPhysicalStock.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
             infoPhysicalStockDetails.Slno = Convert.ToInt32(dgvPhysicalStock.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
             infoPhysicalStockDetails.Extra1 = string.Empty;
             infoPhysicalStockDetails.Extra2 = string.Empty;
             spPhysicalStockDetails.PhysicalStockDetailsAdd(infoPhysicalStockDetails);
             decimal decPId = infoPhysicalStockDetails.ProductId;
             string strVoucher = infoPhysicalStockMaster.VoucherNo;
             AddtoStockPosting(decPId, strVoucher);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PS:23" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Function to get particular values from PhysicalStockDetails table based on the parameter
 /// </summary>
 /// <param name="physicalStockDetailsId"></param>
 /// <returns></returns>
 public PhysicalStockDetailsInfo PhysicalStockDetailsView(decimal physicalStockDetailsId)
 {
     PhysicalStockDetailsInfo physicalstockdetailsinfo = new PhysicalStockDetailsInfo();
     SqlDataReader sdrreader = null;
     try
     {
         if (sqlcon.State == ConnectionState.Closed)
         {
             sqlcon.Open();
         }
         SqlCommand sccmd = new SqlCommand("PhysicalStockDetailsView", sqlcon);
         sccmd.CommandType = CommandType.StoredProcedure;
         SqlParameter sprmparam = new SqlParameter();
         sprmparam = sccmd.Parameters.Add("@physicalStockDetailsId", SqlDbType.Decimal);
         sprmparam.Value = physicalStockDetailsId;
         sdrreader = sccmd.ExecuteReader();
         while (sdrreader.Read())
         {
             physicalstockdetailsinfo.PhysicalStockDetailsId = decimal.Parse(sdrreader[0].ToString());
             physicalstockdetailsinfo.PhysicalStockMasterId = decimal.Parse(sdrreader[1].ToString());
             physicalstockdetailsinfo.ProductId = decimal.Parse(sdrreader[2].ToString());
             physicalstockdetailsinfo.Qty = decimal.Parse(sdrreader[3].ToString());
             physicalstockdetailsinfo.Rate = decimal.Parse(sdrreader[4].ToString());
             physicalstockdetailsinfo.UnitId = decimal.Parse(sdrreader[5].ToString());
             physicalstockdetailsinfo.UnitConversionId = decimal.Parse(sdrreader[6].ToString());
             physicalstockdetailsinfo.BatchId = decimal.Parse(sdrreader[7].ToString());
             physicalstockdetailsinfo.GodownId = decimal.Parse(sdrreader[8].ToString());
             physicalstockdetailsinfo.RackId = decimal.Parse(sdrreader[9].ToString());
             physicalstockdetailsinfo.Amount = decimal.Parse(sdrreader[10].ToString());
             physicalstockdetailsinfo.Slno = int.Parse(sdrreader[11].ToString());
             physicalstockdetailsinfo.ExtraDate = DateTime.Parse(sdrreader[12].ToString());
             physicalstockdetailsinfo.Extra1 = sdrreader[13].ToString();
             physicalstockdetailsinfo.Extra2 = sdrreader[14].ToString();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
     finally
     {
         sdrreader.Close();
         sqlcon.Close();
     }
     return physicalstockdetailsinfo;
 }