private string GetQuery(string cYear, int cMonth)
        {
            string strsql;

            DataRowView dr1 = (DataRowView)cboDirector.SelectedItem;
            DataRowView dr2 = (DataRowView)cboManager.SelectedItem;

            if (dr2 != null)
            {
                strsql = StrategyMeasures.GetQueryStrategyMeasuresProgress(cYear, cMonth, dr1["director_id"].ToString(), dr2["manager_id"].ToString());
            }
            else
            {
                if (opt2.Checked)
                {
                    strsql = StrategyMeasures.GetQueryStrategyMeasuresProgress(cYear, cMonth);
                }
                else if (opt1.Checked)
                {
                    strsql = StrategyMeasures.GetQueryStrategyMeasuresProgress(cYear, cMonth, OPGlobals.CurrentUser.DirectorID);
                }
                else
                {
                    strsql = StrategyMeasures.GetQueryStrategyMeasuresProgress(cYear, cMonth, OPGlobals.CurrentUser.DirectorID, OPGlobals.CurrentUser.ManagerID);
                }
            }
            return(strsql);
        }
        private bool SaveStrategyMeasureMonthlyProgress()
        {
            bool mRetVal = false;

            DataTable tb;
            string    msg;

            dgv.EndEdit();

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

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            using (DbTransaction trans = conn.BeginTransaction())
            {
                try
                {
                    for (int i = 0; i < dgv.Rows.Count; i++)
                    {
                        if (string.IsNullOrEmpty(dgv.Rows[i].Cells["Progress"].Value.ToString()) && string.IsNullOrEmpty(dgv.Rows[i].Cells["Comments"].Value.ToString()))
                        {
                            continue;
                        }

                        StrategyMeasures sm = new StrategyMeasures();
                        sm.MeasureCode = dgv.Rows[i].Cells["Code"].Value.ToString();
                        sm.StrategyID  = dgv.Rows[i].Cells["strategy_id"].Value.ToString();
                        sm.Year        = OPGlobals.currentYear;
                        sm.Month       = OPGlobals.GetStrategyMeasureMonth();

                        double mProgress;
                        Double.TryParse(dgv.Rows[i].Cells["Progress"].Value.ToString(), out mProgress);
                        sm.CurrentProgress = mProgress;

                        sm.Comment = dgv.Rows[i].Cells["Comments"].Value.ToString();
                        if (!sm.IsExist())
                        {
                            sm.InsertMonthlyStrategyMeasures(db, conn, trans);
                        }
                        else
                        {
                            sm.UpdateMonthlyStrategyMeasures(db, conn, trans);
                        }

                        //DbConnection conn1 = db.CreateDbConnection(Database.ConnectionType.ConnectionString, OPGlobals.connString);
                        //string t = "SELECT count(strategy_measure_code) as noofrecs FROM  strategy_measure_monthly"
                        //    + " WHERE strategy_measure_code = '" + sm.MeasureCode + "'"
                        //    + " AND strategy_id = '" + sm.StrategyID + "'"
                        //    + " AND year = '" + sm.Year + "' AND month = " + sm.Month;
                        //DataTable tb_temp = db.GetDataTable(conn, t);
                        //if (int.Parse(tb_temp.Rows[0]["noofrecs"].ToString()) == 0)
                        //{
                        //    sm.InsertMonthlyStrategyMeasures(db, conn, trans);
                        //} else
                        //{
                        //    sm.UpdateMonthlyStrategyMeasures(db, conn, trans);
                        //}
                    }
                    trans.Commit();
                    mRetVal = true;
                    //RefreshGridAfterSaveData();
                    msg = "Strategy Measures Monthly Progress has been saved/updated successfully";
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    msg = "Data NOT Saved ..." + Environment.NewLine + ex.Message;
                }
            }

            conn.Close();
            MessageBox.Show(msg, "OPERATION PLAN", MessageBoxButtons.OK, MessageBoxIcon.Information);

            return(mRetVal);
        }