Ejemplo n.º 1
0
        public void GetGRNNo()
        {
            List <GRNEntity> lstGRNNo = new List <GRNEntity>();


            Execute objExecute = new Execute();
            string  Query      = "[dbo].[spGetGRNNo]";

            SqlParameter[] para = new SqlParameter[]
            {
                Execute.AddParameter("@intSupplierID", Convert.ToInt32(cmbSupplier.SelectedValue)),
            };
            DataTable dt = (DataTable)objExecute.Executes(Query, ReturnType.DataTable, para, CommandType.StoredProcedure);

            foreach (DataRow dr in dt.Rows)
            {
                objGRNEntity = new GRNEntity
                {
                    intGRNHeaderID = Convert.ToInt32(dr["intGRNHeaderID"]),
                    vcGRNNo        = dr["vcGRNNo"].ToString()
                };

                lstGRNNo.Add(objGRNEntity);
            }

            cmbGRNNo.DataSource    = lstGRNNo;
            cmbGRNNo.DisplayMember = "vcGRNNo";
            cmbGRNNo.ValueMember   = "intGRNHeaderID";
            cmbGRNNo.SelectedIndex = -1;
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (cmbSupplier.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select the Supplier");
                    return;
                }
                //else if (cmbBrand.SelectedIndex == -1)
                //{
                //    MessageBox.Show("Please select the Brand");
                //    return;
                //}
                //else if (cmbMainCategory.SelectedIndex == -1)
                //{
                //    MessageBox.Show("Please select the Main Category");
                //    return;
                //}
                //else if (cmbSubCat.SelectedIndex == -1)
                //{
                //    MessageBox.Show("Please select the Sub Category");
                //    return;
                //}

                if (dgvGRN.Rows.Count == 0)
                {
                    MessageBox.Show("Please Item Add to Grid");
                    return;
                }

                foreach (DataGridViewRow row in dgvGRN.Rows)
                {
                    if (Convert.ToBoolean(row.Cells[dgvGRN.Columns[clmGRNQty.Name].Index].Value == null) || (Convert.ToInt32(row.Cells[dgvGRN.Columns[clmGRNQty.Name].Index].Value) == 0))
                    {
                        MessageBox.Show("Please Enter GRN Qty");
                        return;
                    }
                    if (Convert.ToBoolean(row.Cells[dgvGRN.Columns[clmUnitPrice.Name].Index].Value == null) || (Convert.ToInt32(row.Cells[dgvGRN.Columns[clmUnitPrice.Name].Index].Value) == 0))
                    {
                        MessageBox.Show("Please Enter Unit Price Qty");
                        return;
                    }
                }

                DialogResult drs = MessageBox.Show("Are You Sure All Infromation Correct?", "CONFIRM", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);

                if (drs == DialogResult.Yes)
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        intGRNHeaderID = 0;
                        List <GRNEntity> lstGRNSave = new List <GRNEntity>();

                        Execute        objExecute = new Execute();
                        SqlParameter[] param      = new SqlParameter[]
                        {
                            Execute.AddParameter("@intSupplierID", Convert.ToInt32(cmbSupplier.SelectedValue))
                        };

                        intGRNHeaderID = objExecute.ExecuteIdentity("spSaveGRNHeader", param, CommandType.StoredProcedure);

                        foreach (DataGridViewRow dr in dgvGRN.Rows)
                        {
                            GRNEntity objGRNEntity = new GRNEntity
                            {
                                intGRNHeaderID     = intGRNHeaderID,
                                intItemID          = Convert.ToInt32(dr.Cells[clmItemID1.Name].Value.ToString()),
                                decGRNQty          = Convert.ToDecimal(dr.Cells[clmGRNQty.Name].Value.ToString()),
                                decUnitPrice       = Convert.ToDecimal(dr.Cells[clmUnitPrice.Name].Value.ToString()),
                                decDiscountedValue = Convert.ToDecimal(dr.Cells[clmDiscountedValue.Name].Value.ToString()),
                            };
                            lstGRNSave.Add(objGRNEntity);
                        }

                        foreach (GRNEntity item in lstGRNSave)
                        {
                            Execute        objExecuteX = new Execute();
                            SqlParameter[] paramX      = new SqlParameter[]
                            {
                                Execute.AddParameter("@intGRNHeaderID", item.intGRNHeaderID),
                                Execute.AddParameter("@intItemID", item.intItemID),
                                Execute.AddParameter("@decGRNQty", item.decGRNQty),
                                Execute.AddParameter("@decUnitPrice", item.decUnitPrice),
                                Execute.AddParameter("@decDiscountedValue", item.decDiscountedValue),
                            };

                            objExecuteX.Executes("spSaveGRNDetails", paramX, CommandType.StoredProcedure);
                        }

                        ts.Complete();
                    }

                    MessageBox.Show("Save..");

                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

                    ///Report///////////////////////////////////////////////////
                    ///
                    rptGRN         rpt    = new rptGRN();
                    ReportDocument rptDoc = new ReportDocument();

                    rptDoc = rpt;

                    Execute        objExecuteXX = new Execute();
                    string         Query        = "[dbo].[spGetGRNReportDetails]";
                    SqlParameter[] para         = new SqlParameter[]
                    {
                        Execute.AddParameter("@intGRNHeaderID", intGRNHeaderID)
                    };
                    DataTable dt = (DataTable)objExecuteXX.Executes(Query, ReturnType.DataTable, para, CommandType.StoredProcedure);

                    rpt.SetDataSource(dt);

                    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;

                    frmReportViewer objfrmReportViewer = new frmReportViewer(rptDoc);
                    objfrmReportViewer.Show();

                    //rptDoc.PrintToPrinter(1, true, 0, 0);

                    clear();

                    //////////////////////////////b
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Data Saving Error");
                Logger.LoggError(ex, "btnSave_Click");
            }
        }