示例#1
0
        /// <summary>
        /// Function to call save or edit function
        /// </summary>
        public void SaveOrEdit()
        {
            bool Isexit = false;
            StockJournalMasterSP spStockJournalMaster = new StockJournalMasterSP();
            try
            {
                dgvConsumption.ClearSelection();
                dgvProduction.ClearSelection();
                dgvAdditionalCost.ClearSelection();
                int inRowConsumption = dgvConsumption.RowCount;
                int inRowProduction = dgvProduction.RowCount;

                if (txtVoucherNo.Text.Trim() == string.Empty)
                {
                    Messages.InformationMessage("Enter voucher number");
                    txtVoucherNo.Focus();
                }
                else if (spStockJournalMaster.StockJournalInvoiceNumberCheckExistence(txtVoucherNo.Text.Trim(), 0, decVoucherTypeId) == true && btnSave.Text == "Save")
                {
                    Messages.InformationMessage("Invoice number already exist");
                    txtVoucherNo.Focus();
                }
                else if (txtDate.Text.Trim() == string.Empty)
                {
                    Messages.InformationMessage("Select a date in between financial year");
                    txtDate.Focus();
                }
                else if (cmbCurrency.SelectedIndex == -1)
                {
                    Messages.InformationMessage("Select any currency");
                    cmbCurrency.Focus();
                }
                else
                {
                    if (rbtnManufacturing.Checked)
                    {
                        if (inRowConsumption - 1 == 0)
                        {
                            Messages.InformationMessage("Can't save Stock Journal without atleast one product with complete details");
                            dgvConsumption.Focus();
                            goto Exit;
                        }
                        if (inRowProduction - 1 == 0)
                        {
                            Messages.InformationMessage("Can't save Stock Journal without atleast one product with complete details");
                            dgvProduction.Focus();
                            goto Exit;
                        }

                    }
                    if (rbtnTransfer.Checked)
                    {
                        int indgvRowsConsumption = dgvConsumption.Rows.Count;
                        int indgvRowsProduction = dgvProduction.Rows.Count;

                        if (inRowConsumption - 1 == 0)
                        {
                            Messages.InformationMessage("Can't save Stock Journal without atleast one product with complete details");
                            dgvConsumption.Focus();
                            goto Exit;
                        }
                        if (inRowProduction - 1 == 0)
                        {
                            Messages.InformationMessage("Can't save Stock Journal without atleast one product with complete details");
                            dgvProduction.Focus();
                            goto Exit;
                        }
                        if (indgvRowsConsumption != indgvRowsProduction)
                        {
                            Messages.InformationMessage("Please Tranfer the details");
                            goto Exit;
                        }
                        for (int i = 0; i < dgvProduction.Rows.Count - 1; i++)
                        {
                            decimal dcConsumption = 0;
                            decimal dcProduction = 0;
                            dcConsumption = Convert.ToDecimal(dgvConsumption.Rows[i].Cells["dgvtxtConsumptionQty"].Value);
                            dcProduction = Convert.ToDecimal(dgvProduction.Rows[i].Cells["dgvtxtProductionQty"].Value);
                            if (dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value == null || dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value.ToString() == "1")
                            {

                                Messages.InformationMessage("Rows Contains Invalid entries please fill the Godown Details");
                                goto Exit;
                            }
                            if (dgvConsumption.Rows[i].Cells["dgvcmbConsumptionGodown"].Value.ToString() == dgvProduction.Rows[i].Cells["dgvcmbProductionGodown"].Value.ToString())
                            {
                                Messages.InformationMessage(" The Godown should be different");
                                dgvProduction.Focus();
                                Isexit = true;
                                break;
                            }
                            if (dcConsumption != dcProduction)
                            {

                                Messages.InformationMessage("The Quantity Should be Same");
                                goto Exit;
                            }

                        }
                    }
                    if (rbtnStockOut.Checked)
                    {
                        if (inRowConsumption - 1 == 0)
                        {
                            Messages.InformationMessage("Can't save Stock Journal without atleast one product with complete details");
                            dgvConsumption.Focus();

                            goto Exit;
                        }
                    }
                    if (!Isexit)
                    {
                        if (RemoveIncompleteRowsFromConsumptionGrid())
                        {
                            if (!rbtnStockOut.Checked)
                            {
                                if (RemoveIncompleteRowsFromProductionGrid())
                                {
                                    if (dgvConsumption.Rows[0].Cells["dgvtxtConsumptionProductName"].Value == null && dgvConsumption.Rows[0].Cells["dgvtxtConsumptionQty"].Value == null || dgvProduction.Rows[0].Cells["dgvtxtProductionProductName"].Value == null && dgvProduction.Rows[0].Cells["dgvtxtProductionQty"].Value == null)
                                    {
                                        MessageBox.Show("Can't save Stock Journal without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        dgvConsumption.ClearSelection();
                                        dgvConsumption.Focus();
                                        goto Exit;
                                    }
                                    else
                                    {
                                        if (btnSave.Text == "Save")
                                        {

                                            if (Messages.SaveConfirmation())
                                            {
                                                grandTotalAmountCalculationConsumption();
                                                grandTotalAmountCalculationProduction();
                                                Save();
                                            }

                                        }
                                        if (btnSave.Text == "Update")
                                        {
                                            if (Messages.UpdateConfirmation())
                                            {
                                                grandTotalAmountCalculationConsumption();
                                                grandTotalAmountCalculationProduction();
                                                Save();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (dgvConsumption.Rows[0].Cells["dgvtxtConsumptionProductName"].Value == null || dgvConsumption.Rows[0].Cells["dgvtxtConsumptionProductName"].Value.ToString() == string.Empty && dgvConsumption.Rows[0].Cells["dgvtxtConsumptionQty"].Value == null)
                                {
                                    MessageBox.Show("Can't save Stock Journals without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    dgvConsumption.ClearSelection();
                                    dgvConsumption.Focus();
                                    goto Exit;
                                }
                                if (btnSave.Text == "Save")
                                {
                                    if (Messages.SaveConfirmation())
                                    {
                                        grandTotalAmountCalculationConsumption();
                                        Save();
                                    }
                                }
                                if (btnSave.Text == "Update")
                                {
                                    if (Messages.UpdateConfirmation())
                                    {
                                        grandTotalAmountCalculationConsumption();
                                        Save();

                                    }
                                }

                            }
                        }
                    }
                }

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