private void tsbSave_Click(object sender, EventArgs e)
        {
            int startIndex = CapitalWork.getNextCPWIndexStatic();

            for (int dr = 0; dr < dg1.RowCount; dr++)
            {
                CapitalWork cpw = new CapitalWork(dr + startIndex);
                cpw.CapitalWorkJobCostNumber = dg1.Rows[dr].Cells["JCNo"].Value.ToString();
                cpw.Description = dg1.Rows[dr].Cells["Description"].Value.ToString();

                cpw.OriginalBudget = Double.Parse(string.IsNullOrEmpty(dg1.Rows[dr].Cells["Org.Budget"].Value.ToString()) ? "0" : dg1.Rows[dr].Cells["Org.Budget"].Value.ToString(),
                                                  NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands);

                cpw.RevisedBudget = Double.Parse(string.IsNullOrEmpty(dg1.Rows[dr].Cells["Rev.Budget"].Value.ToString()) ? "0" : dg1.Rows[dr].Cells["Rev.Budget"].Value.ToString(),
                                                 NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands);

                cpw.ServicePlanID = dg1.Rows[dr].Cells["ServiceID"].Value.ToString();
                cpw.ManagerID     = dg1.Rows[dr].Cells["ManagerID"].Value.ToString();

                cpw.CapitalWorkYear  = OPGlobals.currentYear;
                cpw.CapitalWorkMonth = OPGlobals.currentMonth;
                cpw.YearToDate       = Double.Parse(string.IsNullOrEmpty(dg1.Rows[dr].Cells["YTD"].Value.ToString()) ? "0" : dg1.Rows[dr].Cells["YTD"].Value.ToString(),
                                                    NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands);


                DbConnection conn = db.CreateDbConnection(Database.ConnectionType.ConnectionString, OPGlobals.connString);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                using (DbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        bool saveresult = cpw.InsertCWP(db, conn, trans);
                        if (saveresult)
                        {
                            cpw.InsertCWPQBR(db, conn, trans);
                            cpw.InsertCWPYTD(db, conn, trans);
                        }



                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        MessageBox.Show("Data NOT Saved ..." + cpw.Description.ToString() + Environment.NewLine + ex.Message.ToString(), "OP ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            MessageBox.Show("Capital Work Project has been imported successfully", "OP MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#2
0
        private void tsbSave_Click(object sender, EventArgs e)
        {
            bool saveresult = false;
            //======== NEW CPW===========
            CapitalWork cpw = new CapitalWork((string.IsNullOrEmpty(txtcpwid.Text) ? 0 : int.Parse(txtcpwid.Text)));

            cpw.CapitalWorkJobCostNumber = txtJobCostNumber.Text;

            DataRowView row;

            row = (DataRowView)cboManager.SelectedItem;
            if (row != null)
            {
                cpw.ManagerID = row["manager_id"].ToString();
            }

            cpw.CapitalWorkYear  = txtFinYear.Text;
            cpw.CapitalWorkMonth = OPGlobals.currentMonth;

            row = (DataRowView)cboServicePlan.SelectedItem;
            if (row != null)
            {
                cpw.ServicePlanID = row["id"].ToString();
            }

            row = (DataRowView)cboStrategyObj.SelectedItem;
            if (row != null)
            {
                cpw.StrategyObjectiveID = row["id"].ToString();
            }

            cpw.Description = txtCPWDescription.Text;

            double number;

            if (Double.TryParse(txtCPWBudget.Text, out number))
            {
                cpw.OriginalBudget = number;
            }
            if (Double.TryParse(txtRevisedBudget.Text, out number))
            {
                cpw.RevisedBudget = number;
            }
            if (Double.TryParse(txtCarryOver.Text, out number))
            {
                cpw.CarryOverBudget = number;
            }

            DbConnection conn = db.CreateDbConnection(Database.ConnectionType.ConnectionString, OPGlobals.connString);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            using (DbTransaction trans = conn.BeginTransaction())
            {
                try
                {
                    if (cpw.CapitalWorkID == 0)
                    {
                        saveresult = cpw.InsertCWP(db, conn, trans);
                        if (saveresult)
                        {
                            cpw.InsertCWPQBR(db, conn, trans);
                        }
                    }
                    else
                    {
                        saveresult = cpw.UpdateCWP(db, conn, trans);
                        if (saveresult)
                        {
                            cpw.UpdateCWPQBR(db, conn, trans);
                        }
                    }

                    trans.Commit();
                    MessageBox.Show("Capital Work Project has been saved/updated successfully", "OP MESSAGE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    MessageBox.Show("Data NOT Saved ..." + Environment.NewLine + ex.Message.ToString(), "OP ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            conn.Close();
            if (saveresult == true)
            {
                UpdateDataGrid(cpw.CapitalWorkID);
            }
        }
        private void tsbSave_Click(object sender, EventArgs e)
        {
            var    exists   = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1;
            bool   opstatus = true;
            string msg      = "<<<<<<< OPERATION SUMMARY >>>>>>>" + Environment.NewLine;

            pb1.Value   = 0;
            pb1.Maximum = dgv01.RowCount + 1;
            pb1.Visible = true;
            double      projected;
            double      revised;
            CapitalWork cw;

            DbConnection conn = db.CreateDbConnection(Database.ConnectionType.ConnectionString, OPGlobals.connString);

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }

            using (DbTransaction trans = conn.BeginTransaction())
            {
                for (int i = 0; i < dgv01.RowCount; i++)
                {
                    dgv01.CurrentCell = dgv01.Rows[i].Cells[0];
                    pb1.Value++;
                    try
                    {
                        projected = Double.Parse(string.IsNullOrEmpty(dgv01.Rows[i].Cells["Projected"].Value.ToString()) ? "0" : dgv01.Rows[i].Cells["Projected"].Value.ToString(),
                                                 NumberStyles.AllowCurrencySymbol | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint);
                        revised = Double.Parse(string.IsNullOrEmpty(dgv01.Rows[i].Cells["Rev.Budget"].Value.ToString()) ? "0" : dgv01.Rows[i].Cells["Rev.Budget"].Value.ToString(),
                                               NumberStyles.AllowCurrencySymbol | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands);
                        if (projected <= 0)
                        {
                            continue;
                        }
                        cw = new CapitalWork(int.Parse(dgv01.Rows[i].Cells["cpwID"].Value.ToString()));
                        cw.CapitalWorkYear  = OPGlobals.currentYear;
                        cw.CapitalWorkMonth = OPGlobals.currentMonth;
                        cw.RevisedBudget    = projected;
                        if (!cw.InsertCWPQBR(db, conn, trans))
                        {
                            cw.UpdateCWPQBR(db, conn, trans);
                        }
                    }
                    catch (NullReferenceException ex1)
                    {
                        continue;
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        msg = ex.Message;
                        break;
                    }
                }
                trans.Commit();
                msg += "Data saved successfully";
                LoadTableFromDatabase();
            }
            conn.Close();
            MessageBox.Show(msg, "OPERATION PLAN", MessageBoxButtons.OK, MessageBoxIcon.Information);
            pb1.Visible = false;
        }