private void gcTopend_ColumnEdit_EditValueChanged(object sender, EventArgs e)
        {
            DevExpress.XtraEditors.CheckEdit editor = (sender as DevExpress.XtraEditors.CheckEdit);
            TheTopEndText = editor.Properties.GetDisplayText(editor.EditValue);

            if (activity.EditValue.ToString() == "1")
            {
                string wpDesc = Development.GetRowCellValue(Development.FocusedRowHandle, Development.Columns["description"]).ToString();

                string workplcid;
                string prmonth;
                dt.AcceptChanges();
                DataRow[] df = dt.Select("description='" + wpDesc + "'");
                prmonth   = df[0]["prodmonth"].ToString();
                workplcid = df[0]["workplaceid"].ToString();

                if (TheTopEndText == "True")
                {
                    MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                    _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                    _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                    _dbMan.SqlStatement       = "update PLANMONTH SET Topend = 'Y' WHERE prodmonth=" + prmonth + " and workplaceid='" + workplcid + "' and Plancode ='LP' ";

                    _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                    _dbMan.ExecuteInstruction();
                }
                else
                {
                    MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                    _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                    _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                    _dbMan.SqlStatement       = "update PLANMONTH SET Topend = 'N' WHERE prodmonth=" + prmonth + " and workplaceid='" + workplcid + "' and Plancode ='LP' ";

                    _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                    _dbMan.ExecuteInstruction();
                }
            }
        }
        private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            if (activity.EditValue.ToString() == "0")
            {
                Stopping.PostEditor();
                Stopping.UpdateCurrentRow();
                foreach (DataRow r in dt.Rows)
                {
                    string auth;
                    if (r["Auth"].ToString() != "")
                    {
                        if (Convert.ToBoolean(r["Auth"].ToString()) == true)
                        {
                            auth = "Y";
                        }
                        else
                        {
                            auth = "N";
                        }
                    }

                    else
                    {
                        auth = "N";
                    }
                    if (r.RowState == DataRowState.Modified)
                    {
                        MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                        _dbMan.ConnectionString = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                        sb.AppendLine("update PLANMONTH SET Locked='" + r["locked"].ToString() + "',");
                        sb.AppendLine("                     Auth = '" + auth + "'");

                        sb.AppendLine("  WHERE prodmonth=" + r["prodmonth"].ToString() + " and workplaceid='" + r["workplaceid"].ToString() + "' and Plancode ='LP' and sectionid='" + r["Sectionid"].ToString() + "' ");
                        _dbMan.SqlStatement       = sb.ToString();
                        _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                        _dbMan.queryReturnType    = MWDataManager.ReturnType.DataTable;
                        _dbMan.ExecuteInstruction();
                        TUserInfo.ActionLog(resWPAS.systemTag, "LOCK PLAN STOPE", UserCurrentInfo.UserID + " : " + r["workplaceid"].ToString() + " LOCKED: " + r["locked"].ToString(), UserCurrentInfo.Connection);
                        TUserInfo.ActionLog(resWPAS.systemTag, "LOCK PLAN STOPE", UserCurrentInfo.UserID + " : " + r["workplaceid"].ToString() + " AUTH: " + r["Auth"].ToString(), UserCurrentInfo.Connection);
                    }
                }
            }

            if (activity.EditValue.ToString() == "1")
            {
                Development.PostEditor();

                Development.UpdateCurrentRow();
                foreach (DataRow r in dt.Rows)
                {
                    string auth;
                    if (r["Auth"].ToString() == "" || Convert.ToBoolean(r["Auth"].ToString()) == false)
                    {
                        auth = "N";
                    }
                    else
                    {
                        auth = "Y";
                    }
                    bool   locked;
                    var    descript = Development.GetRowCellValue(Development.FocusedRowHandle, Development.Columns["description"]);
                    string DESCRIPT = Convert.ToString(descript);
                    var    LOCKED   = Development.GetRowCellValue(Development.FocusedRowHandle, Development.Columns["locked"]);
                    if (LOCKED == null || LOCKED is DBNull || LOCKED == "")
                    {
                        LOCKED = "False";
                        locked = Convert.ToBoolean(LOCKED);
                    }
                    else
                    {
                        locked = Convert.ToBoolean(LOCKED);
                    }

                    bool Lock;
                    if (r["locked"].ToString() == "")
                    {
                        Lock = false;
                    }
                    else
                    {
                        Lock = Convert.ToBoolean(r["locked"].ToString());
                    }
                    var    ab10  = Development.GetRowCellValue(Development.FocusedRowHandle, Development.Columns["Topend"]);
                    string ab101 = Convert.ToString(ab10);
                    string workplcid;
                    string prmonth;
                    dt.AcceptChanges();
                    DataRow[] df = dt.Select("description='" + DESCRIPT + "'");
                    prmonth   = df[0]["prodmonth"].ToString();
                    workplcid = df[0]["workplaceid"].ToString();

                    MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                    _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                    _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                    _dbMan.SqlStatement       = "";
                    //_dbMan.SqlStatement = "update PLANMONTH SET  Auth = '" + auth + "', cmkgt = " + r["Lcmkgt"].ToString() + ", Locked=" + Convert.ToInt16(Lock).ToString() + ",metresadvance=" + r["lM"].ToString() + ",ReefAdv=" + r["Lock_On_M"].ToString() + ",WasteAdv=" + r["Lock_Off_M"].ToString() + " WHERE prodmonth=" + prmonth + " and workplaceid='" + r["Workplaceid"].ToString() + "'  and Plancode ='LP'  and sectionid='" + r["Sectionid"].ToString() + "'";
                    _dbMan.SqlStatement    = "update PLANMONTH SET  Auth = '" + auth + "',Locked=" + Convert.ToInt16(Lock).ToString() + "  WHERE prodmonth=" + prmonth + " and workplaceid='" + r["Workplaceid"].ToString() + "'  and Plancode ='LP'  and sectionid='" + r["Sectionid"].ToString() + "'";
                    _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                    _dbMan.ExecuteInstruction();
                    rpReplanning.Visible  = true;
                    rpPreplanning.Visible = false;
                    gcLockPlan.Visible    = true;
                    TUserInfo.ActionLog(resWPAS.systemTag, "LOCK PLAN STOPE", UserCurrentInfo.UserID + " : " + r["workplaceid"].ToString() + " LOCKED: " + r["locked"].ToString(), UserCurrentInfo.Connection);
                    TUserInfo.ActionLog(resWPAS.systemTag, "LOCK PLAN STOPE", UserCurrentInfo.UserID + " : " + r["workplaceid"].ToString() + " AUTH: " + r["Auth"].ToString(), UserCurrentInfo.Connection);
                }

                gcLockPlan.Visible    = false;
                rpPreplanning.Visible = true;
                rpReplanning.Visible  = false;
                panelControl1.Visible = false;
                //Mineware.Systems.Global.sysNotification.TsysNotification.showNotification("Data Saved", "Development Lock Plan Data was saved successfully", Color.CornflowerBlue);
            }

            if (activity.EditValue.ToString() == "2")
            {
                Sundry.PostEditor();
                Sundry.UpdateCurrentRow();

                foreach (DataRow r in dt.Rows)
                {
                    bool Auth;
                    if (r["Auth"].ToString() == "")
                    {
                        Auth = false;
                    }
                    else
                    {
                        Auth = Convert.ToBoolean(r["Auth"].ToString());
                    }

                    bool Lock;
                    if (r["Locked"].ToString() == "")
                    {
                        Lock = false;
                    }
                    else
                    {
                        Lock = Convert.ToBoolean(r["Locked"].ToString());
                    }

                    if (Convert.ToBoolean(r["hasChanged"].ToString()) == true) // only save data that changed
                    {
                        MWDataManager.clsDataAccess _dbMan1 = new MWDataManager.clsDataAccess();
                        _dbMan1.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                        _dbMan1.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                        _dbMan1.SqlStatement       = "";
                        _dbMan1.SqlStatement       = "select * from PLANMONTH_SUNDRYMINING WHERE prodmonth=" + r["prodmonth"].ToString() + " and workplaceid='" + r["Workplaceid"].ToString() + "'  and Plancode ='LP' and SMID='" + r["SMID"].ToString() + "' and sectionid='" + r["Sectionid"].ToString() + "'";

                        _dbMan1.queryReturnType = MWDataManager.ReturnType.DataTable;
                        _dbMan1.ExecuteInstruction();
                        DataTable SNDRY = new DataTable();
                        SNDRY.Clear();
                        SNDRY = _dbMan1.ResultsDataTable;
                        if (SNDRY.Rows.Count == 0)
                        {
                            MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                            _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                            _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                            _dbMan1.SqlStatement      = "";
                            _dbMan.SqlStatement       = " insert into PLANMONTH_SUNDRYMINING values(" + r["prodmonth"].ToString() + ",'" + r["SectionID"].ToString() + "','" + r["Workplaceid"].ToString() + "',2,'" + r["SMID"].ToString() + "','LP'," +
                                                        "   '" + r["OrgunitDay"].ToString() + "', " +
                                                        "    '" + r["OrgunitNight"].ToString() + "', '" + Convert.ToInt32(r["Units"]) + "','','',0,0.000," + Convert.ToInt16(Lock).ToString() + "," + Convert.ToInt16(Auth).ToString() + ",'') ";
                            _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                            _dbMan.ExecuteInstruction();
                            rpReplanning.Visible  = true;
                            rpPreplanning.Visible = false;
                            gcLockPlan.Visible    = true;
                        }
                        else
                        {
                            MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                            _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                            _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                            _dbMan.SqlStatement       = "";
                            _dbMan.SqlStatement       = "update PLANMONTH_SUNDRYMINING SET Locked= " + Convert.ToInt16(Lock).ToString() + " , Auth= " + Convert.ToInt16(Auth).ToString() + " WHERE prodmonth=" + r["prodmonth"].ToString() + " and workplaceid='" + r["Workplaceid"].ToString() + "'  and Plancode ='LP' AND SMID= '" + r["SMID"].ToString() + "' and sectionid='" + r["Sectionid"].ToString() + "'";

                            _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                            _dbMan.ExecuteInstruction();
                            rpReplanning.Visible  = true;
                            rpPreplanning.Visible = false;
                            gcLockPlan.Visible    = true;
                            panelControl1.Visible = true;
                        }
                    }
                }
            }


            if (activity.EditValue.ToString() == "8")
            {
                foreach (DataRow r in dt.Rows)
                {
                    if (Convert.ToBoolean(r["hasChanged"].ToString()) == true) // only save data that changed
                    {
                        // test if WP was saved
                        MWDataManager.clsDataAccess _dbMan1 = new MWDataManager.clsDataAccess();
                        _dbMan1.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                        _dbMan1.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                        _dbMan1.SqlStatement       = "";
                        _dbMan1.SqlStatement       = "select * from PlanMonth_Oldgold WHERE prodmonth=" + r["prodmonth"].ToString() + " and workplaceid='" + r["workplaceid"].ToString() + "'  and Plancode ='LP' AND OGID= '" + r["OGID"].ToString() + "' and sectionid='" + r["Sectionid"].ToString() + "'";

                        _dbMan1.queryReturnType = MWDataManager.ReturnType.DataTable;
                        _dbMan1.ExecuteInstruction();

                        DataTable oldgold = new DataTable();
                        oldgold.Clear();
                        oldgold = _dbMan1.ResultsDataTable;
                        SweepsVamps.PostEditor();
                        SweepsVamps.UpdateCurrentRow();
                        bool Auth;
                        if (r["Auth"].ToString() == "")
                        {
                            Auth = false;
                        }
                        else
                        {
                            Auth = Convert.ToBoolean(r["Auth"].ToString());
                        }

                        bool Lock;
                        if (r["Locked"].ToString() == "")
                        {
                            Lock = false;
                        }
                        else
                        {
                            Lock = Convert.ToBoolean(r["Locked"].ToString());
                        }

                        if (oldgold.Rows.Count == 0) // add
                        {
                            MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                            _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                            _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                            _dbMan.SqlStatement       = "";
                            _dbMan.SqlStatement       = " insert into PLANMONTH_OLDGOLD values(" + r["prodmonth"].ToString() + ",'" + r["SectionID"].ToString() + "','" + r["workplaceid"].ToString() + "',8,'LP','" + r["OGID"].ToString() + "'," +
                                                        " '" + Convert.ToInt32(r["Units"]) + "',0,0.00,0,'" + r["OrgunitDay"].ToString() + "','" + r["OrgunitAfterNoon"].ToString() + "', " +
                                                        " '" + r["OrgunitNight"].ToString() + "',0," + Convert.ToInt16(Lock).ToString() + "," + Convert.ToInt16(Auth).ToString() + ",'') ";
                            _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                            _dbMan.ExecuteInstruction();
                        }
                        else // update
                        {
                            MWDataManager.clsDataAccess _dbMan = new MWDataManager.clsDataAccess();
                            _dbMan.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                            _dbMan.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
                            _dbMan.SqlStatement       = "";
                            _dbMan.SqlStatement       = "update PlanMonth_Oldgold SET Locked= " + Convert.ToInt16(Lock).ToString() + " , Auth= " + Convert.ToInt16(Auth).ToString() + " WHERE prodmonth=" + r["prodmonth"].ToString() + " and workplaceid='" + r["workplaceid"].ToString() + "'  and Plancode ='LP' AND OGID= '" + r["OGID"].ToString() + "' and sectionid='" + r["Sectionid"].ToString() + "'";

                            _dbMan.queryReturnType = MWDataManager.ReturnType.DataTable;
                            _dbMan.ExecuteInstruction();
                        }
                    }
                }
            }
            Mineware.Systems.Global.sysNotification.TsysNotification.showNotification("Success", "Data Saved", System.Drawing.Color.CornflowerBlue);
            ribbonMenu.Minimized = false;
        }