Example #1
0
        /// <summary>
        /// Function to use the Fill the Grid Corresponding To DeliveryNote No
        /// </summary>
        public void FillGridCorrespondingToDeliveryNoteNo()
        {
            try
            {
                dgvProduct.Rows.Clear();
                DeliveryNoteDetailsSP SPDeliveryNoteDetails = new DeliveryNoteDetailsSP();
                DataTable dtbldeliverynotedetails = SPDeliveryNoteDetails.DeliveryNoteDetailsViewByDeliveryNoteMasterIdWithPending(Convert.ToDecimal(cmbDeliveryNoteNo.SelectedValue), decRejectionInIdToEdit);
                foreach (DataRow drdeliverynotedetails in dtbldeliverynotedetails.Rows)
                {
                    isDoCellValueChange = false;
                    isDoAfterGridFill = false;
                    DGVGodownComboFill();
                    dgvProduct.Rows.Add();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxtBarcode"].Value = drdeliverynotedetails["barcode"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxtProductId"].Value = drdeliverynotedetails["productId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxDeliveryNoteDetailsId"].Value = drdeliverynotedetails.ItemArray[0].ToString();
                    AssignProductDefaultValues(dgvProduct.Rows.Count - 1, Convert.ToDecimal(drdeliverynotedetails.ItemArray[2].ToString()));
                    DGVBatchComboFill(dgvProduct.Rows.Count - 1, Convert.ToDecimal(drdeliverynotedetails.ItemArray[2].ToString()));
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxtQuantity"].Value = drdeliverynotedetails["qty"].ToString();
                    isDoCellValueChange = true;
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drdeliverynotedetails["unitId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(drdeliverynotedetails["godownId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvcmbRack"].Value = Convert.ToDecimal(drdeliverynotedetails["rackId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drdeliverynotedetails["batchId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxtRate"].Value = drdeliverynotedetails["rate"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 1].Cells["dgvtxtAmount"].Value = drdeliverynotedetails["amount"].ToString();
                    dgvProduct.CurrentCell = null;


                }
                SerialNo();
                CalcTotalAmt();
                isDoCellValueChange = true;
                isDoAfterGridFill = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("RI :12" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #2
0
        /// <summary>
        /// Doing the basic calculations in grid cell value change
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvProduct_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (isDoCellValueChange)
                {
                    decimal decOldQty = 0;
                    decimal decCurQty = 0;
                    decimal decNewAmount = 0;
                    if (e.RowIndex != -1 && e.ColumnIndex != -1)
                    {
                        if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbGodown")
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value != null)
                            {

                                DGVRackComboFill(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbGodown"].Value.ToString()), dgvProduct, e.RowIndex);
                            }
                        }
                        if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbBatch")
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value != null)
                            {
                                ProductSP SpProduct = new ProductSP();
                                decimal decRate = SpProduct.SalesInvoiceProductRateForSales(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value), dtpDate.Value, Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value), Convert.ToDecimal(cmbPricingLevel.SelectedValue), PublicVariables._inNoOfDecimalPlaces);
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decRate / Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value), PublicVariables._inNoOfDecimalPlaces);
                                BatchSP SpBatch = new BatchSP();
                                dgvProduct.Rows[e.RowIndex].Cells["dgvtxtBarcode"].Value = SpBatch.ProductBatchBarcodeViewByBatchId(Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvcmbBatch"].Value));
                            }
                        }
                        //------------Hided when asked Rejection In not to need unit conversion process -------------------

                        //if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
                        //{
                        //    if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtproductId"].Value.ToString() != string.Empty)
                        //    {
                        //        if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString() != string.Empty)
                        //        {
                        //            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString() != string.Empty)
                        //            {
                        //                decCurrentConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                        //                decCurrentRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                        //            }
                        //        }
                        //    }

                        //}

                        if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQuantity")
                        {
                            DeliveryNoteDetailsInfo infodeliverynotedetails = new DeliveryNoteDetailsInfo();
                            DeliveryNoteDetailsSP spdeliverynotedetails = new DeliveryNoteDetailsSP();
                            DataTable dtbl = spdeliverynotedetails.DeliveryNoteDetailsViewByDeliveryNoteMasterIdWithPending(Convert.ToDecimal(cmbDeliveryNoteNo.SelectedValue.ToString()), decRejectionInIdToEdit);
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value != null)
                            {
                                DataTable dtblUnitByProduct = new DataTable();
                                UnitConvertionSP SpUnitConvertion = new UnitConvertionSP();
                                dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                                foreach (DataRow drdtbl in dtbl.Rows)
                                {
                                    foreach (DataRow drUnitviewall in dtblUnitByProduct.Rows)
                                    {

                                        if (drdtbl["unitConversionId"].ToString() == drUnitviewall["unitConversionId"].ToString())
                                        {
                                            decimal decCurrentQty = Convert.ToDecimal(drdtbl.ItemArray[3].ToString());
                                            decimal decConRateToDlryNteDtls = Convert.ToDecimal(drUnitviewall.ItemArray[3].ToString());
                                            decimal decCurConRateInGrid = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decOldQty = (decCurrentQty / decConRateToDlryNteDtls) * decCurConRateInGrid;
                                            decOldQty = Math.Round(decOldQty, PublicVariables._inNoOfDecimalPlaces);
                                            decCurQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString());

                                        }
                                    }
                                }
                                if (decCurQty > decOldQty)
                                {
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value = decOldQty;

                                }
                                else if (decCurQty <= decOldQty)
                                {
                                    decimal decrate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value.ToString());
                                    dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = Math.Round(decrate * decCurQty, PublicVariables._inNoOfDecimalPlaces);
                                    CalcTotalAmt();
                                }
                            }
                        }

                        if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
                        {
                            if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null)
                            {
                                DataTable dtblUnitByProduct = new DataTable();
                                UnitConvertionSP SpUnitConvertion = new UnitConvertionSP();
                                dtblUnitByProduct = SpUnitConvertion.UnitConversionIdAndConRateViewallByProductId(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductId"].Value.ToString());
                                foreach (DataRow drUnitByProduct in dtblUnitByProduct.Rows)
                                {
                                    if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() == drUnitByProduct.ItemArray[0].ToString())
                                    {
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtUnitConversionId"].Value = Convert.ToDecimal(drUnitByProduct[2].ToString());
                                        dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value = Convert.ToDecimal(drUnitByProduct.ItemArray[3].ToString());
                                        if (isDoAfterGridFill)
                                        {
                                            decimal decNewConversionRate = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtConversionRate"].Value.ToString());
                                            decCurQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQuantity"].Value.ToString());
                                            decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate);
                                            decNewAmount = (decCurrentRate * decCurQty * decCurrentConversionRate) / decNewConversionRate;
                                            dgvProduct.Rows[e.RowIndex].Cells["dgvtxtAmount"].Value = Math.Round(decNewAmount);
                                            txtTotalAmount.Text = Math.Round(decNewRate, 2).ToString();
                                            CalcTotalAmt();
                                        }

                                    }
                                }

                            }
                        }


                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("RI:41 " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }