예제 #1
0
        /// <summary>
        /// To fill the details according to the DeliveryNote master Id from frmDeliveryNoteRegister and frmDeliveryNoteReport
        /// </summary>
        public void FillRegisterOrReport()
        {
            try
            {
                DeliveryNoteMasterInfo infoDeliveryNoteMaster = new DeliveryNoteMasterInfo();
                VoucherTypeInfo infoVoucherType = new VoucherTypeInfo();
                VoucherTypeSP spVoucherType = new VoucherTypeSP();
                DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
                DeliveryNoteDetailsSP spDeliveryNoteDetails = new DeliveryNoteDetailsSP();
                SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
                SalesOrderMasterSP spSalesOrderMaster = new SalesOrderMasterSP();
                SalesQuotationMasterInfo infoSalesQuotationMaster = new SalesQuotationMasterInfo();
                SalesQuotationMasterSP spSalesQuotationMaster = new SalesQuotationMasterSP();
                dgvProduct.Rows.Clear();
                isRegisterReportFill = true;
                btnSave.Text = "Update";
                int inRowIndex = 0;
                btnDelete.Enabled = true;
                txtDeliveryNoteNo.ReadOnly = true;
                if (txtDeliveryNoteNo.ReadOnly == true)
                {
                    txtDate.Focus();
                }
                else
                {
                    txtDeliveryNoteNo.Focus();
                }

                infoDeliveryNoteMaster = spDeliveryNoteMaster.DeliveryNoteMasterViewAllByMasterId(decDelivryNoteIdToEdit);
                txtDeliveryNoteNo.Text = infoDeliveryNoteMaster.InvoiceNo;
                strVoucherNo = infoDeliveryNoteMaster.VoucherNo.ToString();
                decDeliveryNoteSuffixPrefixId = Convert.ToDecimal(infoDeliveryNoteMaster.SuffixPrefixId);
                decDeliveryNoteVoucherTypeId = Convert.ToDecimal(infoDeliveryNoteMaster.VoucherTypeId);
                isAutomatic = spVoucherType.CheckMethodOfVoucherNumbering(decDeliveryNoteVoucherTypeId);
                decDeliveryNoteTypeId = decDeliveryNoteVoucherTypeId;
                cmbCashOrParty.SelectedValue = infoDeliveryNoteMaster.LedgerId;
                txtDate.Text = infoDeliveryNoteMaster.Date.ToString("dd-MMM-yyyy");
                cmbPricingLevel.SelectedValue = infoDeliveryNoteMaster.PricinglevelId;
                infoVoucherType = spVoucherType.VoucherTypeView(decDeliveryNoteVoucherTypeId);
                this.Text = infoVoucherType.VoucherTypeName;
                if (infoDeliveryNoteMaster.OrderMasterId != 0)
                {
                    cmbDeliveryMode.Text = "Against Order";
                    infoSalesOrderMaster = spSalesOrderMaster.SalesOrderMasterView(infoDeliveryNoteMaster.OrderMasterId);
                    cmbType.SelectedValue = infoSalesOrderMaster.VoucherTypeId;
                    AgainstOrderComboFill();
                    cmbOrderNo.SelectedValue = infoDeliveryNoteMaster.OrderMasterId;
                }
                else if (infoDeliveryNoteMaster.QuotationMasterId != 0)
                {
                    cmbDeliveryMode.Text = "Against Quotation";
                    infoSalesQuotationMaster = spSalesQuotationMaster.SalesQuotationMasterView(infoDeliveryNoteMaster.QuotationMasterId);
                    cmbType.SelectedValue = infoSalesQuotationMaster.VoucherTypeId;
                    AgainstQuotationComboFill();
                    cmbOrderNo.SelectedValue = infoDeliveryNoteMaster.QuotationMasterId;
                }
                CurrencyComboFill();
                cmbSalesMan.SelectedValue = infoDeliveryNoteMaster.EmployeeId;
                cmbCurrency.SelectedValue = infoDeliveryNoteMaster.ExchangeRateId;
                txtTraspotationCompany.Text = infoDeliveryNoteMaster.TransportationCompany;
                txtNarration.Text = infoDeliveryNoteMaster.Narration;
                txtLRNo.Text = infoDeliveryNoteMaster.LrNo;
                txtTotalAmnt.Text = infoDeliveryNoteMaster.TotalAmount.ToString("00.00");
                DataTable dtblDetails = spDeliveryNoteDetails.DeliveryNoteDetailsViewByDeliveryNoteMasterId(decDelivryNoteIdToEdit);
                foreach (DataRow drowDetails in dtblDetails.Rows)
                {
                    dgvProduct.Rows.Add();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true;
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].Value = drowDetails["barcode"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtDetailsId"].Value = drowDetails["deliveryNoteDetailsId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherNo"].Value = drowDetails["VoucherNo"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtInvoiceNo"].Value = drowDetails["OrderNoOrQuotationNo"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtVoucherTypeId"].Value = drowDetails["VoucherTypeId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductId"].Value = drowDetails["productId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].Value = drowDetails["productCode"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].Value = drowDetails["productName"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["Col"].Value = drowDetails["slNo"].ToString();
                    if (Convert.ToDecimal(drowDetails["orderDetails1Id"].ToString()) == 0)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = 0;
                    }
                    else
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = Convert.ToDecimal(drowDetails["orderDetails1Id"].ToString());
                    }
                    if (Convert.ToDecimal(drowDetails["quotationDetails1Id"].ToString()) != 0)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value = Convert.ToDecimal(drowDetails["quotationDetails1Id"].ToString());
                    }
                    BatchComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].Value = Convert.ToDecimal(drowDetails["batchId"].ToString());
                    UnitComboFill1(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].Value = Convert.ToDecimal(drowDetails["unitId"].ToString());
                    GridGodownComboFill(Convert.ToDecimal(drowDetails["productId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].Value = Convert.ToDecimal(drowDetails["godownId"].ToString());
                    RackComboFill1(Convert.ToDecimal(drowDetails["godownId"].ToString()), dgvProduct.Rows.Count - 2, dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ColumnIndex);
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].Value = Convert.ToDecimal(drowDetails["rackId"].ToString());
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtQty"].Value = drowDetails["qty"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].Value = drowDetails["rate"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtUnitConversionId"].Value = drowDetails["unitConversionId"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtConversionRate"].Value = drowDetails["conversionRate"].ToString();
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtAmount"].Value = drowDetails["amount"].ToString();
                    if (cmbOrderNo.Visible == true)
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                    }
                    if (spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckRejectionIn(decDelivryNoteIdToEdit))
                    {
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtBarcode"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductCode"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtProductName"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbBatch"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbGodown"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbRack"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtRate"].ReadOnly = true;
                        dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvcmbUnit"].ReadOnly = true;
                    }
                    dgvProduct.Rows[dgvProduct.Rows.Count - 2].HeaderCell.Value = "";
                    AmountCalculation("dgvtxtQty", inRowIndex);
                    TotalAmountCalculation();
                }
                if (!isAutomatic)
                {
                    txtDeliveryNoteNo.ReadOnly = false;
                    txtDeliveryNoteNo.Focus();
                }
                isRegisterReportFill = false;
                isDoAfterGridFill = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("DN19: " + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #2
0
 /// <summary>
 ///to change the corresponding values in grid when cells changed 
 /// </summary>
 private void dgvProduct_CellLeave(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         SalesQuotationDetailsSP spQuotationDetails = new SalesQuotationDetailsSP();
         DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty")
         {
             decimal decCurrentQty = 0;
             decimal decOldQty = 0;
             if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString() != string.Empty)
             {
                 if (decDelivryNoteIdToEdit != 0)
                 {
                     if (cmbOrderNo.SelectedIndex != 0)
                     {
                         if (cmbDeliveryMode.Text == "Against Order")
                         {
                             DataTable dtblDetails = new SalesOrderDetailsSP().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(dtblDetails.Rows[0]["qty"].ToString());
                         }
                         else if (cmbDeliveryMode.Text == "Against Quotation")
                         {
                             DataTable dtblQuotationDetails = spQuotationDetails.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             if (dtblQuotationDetails.Rows.Count >= 1)
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[0].Cells["dgvtxtQty"].Value.ToString());
                                 decOldQty = Convert.ToDecimal(dtblQuotationDetails.Rows[0]["qty"].ToString());
                             }
                         }
                         if (spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckRejectionIn(decDelivryNoteIdToEdit))
                         {
                             DataTable dtblRejectionInQty = new DataTable();
                             dtblRejectionInQty = spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckRejectionInQty(decDelivryNoteIdToEdit);
                             decimal decRejectionInQty = decimal.Parse(dtblRejectionInQty.Rows[e.RowIndex]["qty"].ToString());
                             if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(dtblRejectionInQty.Rows[e.RowIndex]["qty"].ToString()))
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             }
                             else
                             {
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decRejectionInQty);
                             }
                         }
                         if (spDeliveryNoteMaster.DeliveryNoteCheckReferenceInSalesInvoice(decDelivryNoteIdToEdit))
                         {
                             DataTable dtblSalesInvoiceQty = new DataTable();
                             dtblSalesInvoiceQty = spDeliveryNoteMaster.DeliveryNoteMasterReferenceCheckSalesInvoiceQty(decDelivryNoteIdToEdit);
                             decimal decSalesInvoiceQty = decimal.Parse(dtblSalesInvoiceQty.Rows[e.RowIndex]["qty"].ToString());
                             if (decimal.Parse(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString()) > decimal.Parse(dtblSalesInvoiceQty.Rows[e.RowIndex]["qty"].ToString()))
                             {
                                 decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             }
                             else
                             {
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value = Convert.ToDecimal(decSalesInvoiceQty);
                             }
                         }
                     }
                     else
                     {
                         Messages.InformationMessage("Select OrderNo");
                         cmbOrderNo.Focus();
                     }
                 }
                 if (decDelivryNoteIdToEdit == 0)
                 {
                     if (Convert.ToInt32(dgvProduct.Rows[dgvProduct.Rows.Count - 2].Cells["dgvtxtOrderDetailsId"].Value) != 0)
                     {
                         if (cmbDeliveryMode.Text == "Against Quotation")
                         {
                             DataTable dtbl1 = spQuotationDetails.SalesQuotationDetailsViewByquotationMasterIdWithRemainingByNotInCurrDN(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(dtbl1.Rows[e.RowIndex]["qty"].ToString());
                         }
                         else if (cmbDeliveryMode.Text == "Against Order")
                         {
                             DataTable dtbl2 = new SalesOrderDetailsSP().SalesOrderDetailsViewBySalesOrderMasterIdWithRemaining(Convert.ToDecimal(cmbOrderNo.SelectedValue.ToString()), decDelivryNoteIdToEdit);
                             decCurrentQty = Convert.ToDecimal(dgvProduct.Rows[e.RowIndex].Cells["dgvtxtQty"].Value.ToString());
                             decOldQty = Convert.ToDecimal(dtbl2.Rows[e.RowIndex]["qty"].ToString());
                         }
                     }
                 }
             }
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvcmbUnit")
         {
             if (dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvtxtProductCode"].Value.ToString() != string.Empty)
             {
                 if (dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value != null && dgvProduct.Rows[e.RowIndex].Cells["dgvcmbUnit"].Value.ToString() != string.Empty)
                 {
                     UnitConvertionSP SpUnitConvertion = new UnitConvertionSP();
                     DataTable dtblUnitByProduct = new DataTable();
                     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.ItemArray[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());
                                 decimal decNewRate = (decCurrentRate * decCurrentConversionRate) / decNewConversionRate;
                                 dgvProduct.Rows[e.RowIndex].Cells["dgvtxtRate"].Value = Math.Round(decNewRate, 2);
                             }
                         }
                     }
                 }
             }
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtQty")
         {
             AmountCalculation("dgvtxtQty", e.RowIndex);
         }
         if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtRate")
         {
             AmountCalculation("dgvtxtRate", e.RowIndex);
         }
         else if (dgvProduct.Columns[e.ColumnIndex].Name == "dgvtxtAmount")
         {
             TotalAmountCalculation();
         }
         CheckInvalidEntries(e);
     }
     catch (Exception ex)
     {
         MessageBox.Show("DN70:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }