private void LoadTheData(string Template, string Section, string ProdMonth, string Activity, string WorkPlace)
        {
            bool Readonly = false;

            MWDataManager.clsDataAccess _Access = new MWDataManager.clsDataAccess();
            _Access.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
            _Access.SqlStatement       = "SELECT * FROM dbo.PlanProt_ProfileAccess PPPA WHERE  PPPA.TemplateID = " + Template + " AND   DepartmentID = '" + TUserInfo.DepartmentID + "'";
            _Access.queryReturnType    = MWDataManager.ReturnType.DataTable;
            _Access.queryExecutionType = MWDataManager.ExecutionType.GeneralSQLStatement;
            _Access.ExecuteInstruction();

            // Setup security to allow lock and unlock of data
            foreach (DataRow r in _Access.ResultsDataTable.Rows)
            {
                if (r["AccessLevel"].ToString() != "True")
                {
                    Readonly = true;
                }
                else
                {
                    Readonly = false;
                }// change back  btnLockData.enabled to false
            }

            // Setup secutity to allow lock of data
            _Access.SqlStatement = "SELECT DISTINCT Name_4,Name_3 ,Name_2 FROM dbo.SECTION_COMPLETE WHERE SECTIONID_2 = '" + barSetion.EditValue.ToString() + "' AND PRODMONTH = " + ProdMonth;
            _Access.ExecuteInstruction();
            string theUnit    = "";
            string theShaft   = "";
            string theSection = "";


            foreach (DataRow r in _Access.ResultsDataTable.Rows)
            {
                theUnit    = r["Name_4"].ToString(); // the new unit
                theShaft   = r["Name_3"].ToString(); // the new shaft
                theSection = r["Name_2"].ToString(); // the new section
            }

            _Access.SqlStatement = "SELECT * FROM dbo.PlanProt_ApproveUsers WHERE ((Unit = '" + theUnit + "' and Section = 'NONE' and Section = 'NONE') OR (Unit = '" + theUnit + "' and Shaft = '" + theShaft + "' and Section = 'NONE') OR (Unit = '" + theUnit + "' and Shaft = '" + theShaft + "'  and Section = '" + theSection + "'))  AND TemplateID = " + Template;
            _Access.ExecuteInstruction();

            btnLockData.Enabled = true;
            foreach (DataRow r in _Access.ResultsDataTable.Rows)
            {
                if (TUserInfo.UserID == r["User1"].ToString() || TUserInfo.UserID == r["User2"].ToString())
                {
                    btnLockData.Enabled = true;
                    break;
                }
                else
                {
                    btnLockData.Enabled = false;
                }                                    //change back btnLockData.Enabled to false
            }



            string WorkplacesID;

            if (WorkPlace == "")
            {
                WorkplacesID = "0";
            }
            else
            {
                WorkplacesID = WorkPlace;
            }
            ucPlanProtDataView = new ucPlanProtDataView {
                theSystemDBTag = this.theSystemDBTag, UserCurrentInfo = this.UserCurrentInfo
            };
            ucPlanProtDataView.Dock   = DockStyle.Fill;
            ucPlanProtDataView.Parent = clientPanel;
            ucPlanProtDataView.loadTemplateData(Convert.ToInt32(ProdMonth),
                                                Section,
                                                Convert.ToInt32(Template),
                                                WorkplacesID,
                                                Convert.ToInt32(Activity),
                                                captureOption, Readonly);


            if (ucPlanProtDataView.mainData.Rows.Count == 0)
            {
                ucPlanProtDataView.Visible = false;
                rpCapture.Visible          = false;
                rpSettings.Visible         = true;

                _sysMessagesClass.viewMessage(Global.MessageType.Info, "ERROR LOADING DATA", this.theSystemTag, "Template", "loadTemplateData", "No Data available for selected settings", Global.ButtonTypes.OK, Global.MessageDisplayType.FullScreen);

                // MessageBox.Show("No Data available for selected settings", "", MessageBoxButtons.OK);
                // frmPlanProtCpature abc = new frmPlanProtCpature();
                //abc.Show();
            }
        }
Esempio n. 2
0
        private void btnApprove_Click(object sender, EventArgs e)
        {
            //foreach (DataRow r in distinctValuesWorkplace.Rows)
            //{
            //    editProdMonth.Text = r["PRODMONTH"].ToString();
            //    editSection.Text = r["SECTIONID"].ToString();
            //    editTemplateName.Text = r["TemplateName"].ToString();
            //    listWorkplace.Items.Add(r["WPDESCRIPTION"].ToString());

            //}

            if (theapproveType == "APPROVE")
            {
                //MWDataManager.clsDataAccess _SaveData = new MWDataManager.clsDataAccess();
                //_SaveData.ConnectionString = TUserInfo.ConnectionString;
                //_SaveData.SqlStatement = "spPlanProt_ApproveData";
                //_SaveData.queryExecutionType = MWDataManager.ExecutionType.StoreProcedure;
                string text      = "";
                string separator = "";
                foreach (DataRow r in distinctValuesWorkplace.Rows)
                {
                    string textCMB = text;
                    MWDataManager.clsDataAccess _RequiredData = new MWDataManager.clsDataAccess();
                    _RequiredData.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                    _RequiredData.SqlStatement       = "sp_RequiredCountOfDataApproval";
                    _RequiredData.queryExecutionType = MWDataManager.ExecutionType.StoreProcedure;

                    if (Convert.ToBoolean(r["canApprove"].ToString()) == true)
                    {
                        SqlParameter[] _paramCollection1 =
                        {
                            _RequiredData.CreateParameter("@Prodmonth",    SqlDbType.Int,      7, Convert.ToInt32(r["PRODMONTH"].ToString())),
                            _RequiredData.CreateParameter("@SectionID ",   SqlDbType.VarChar, 50, r["SECTIONID"].ToString()),
                            _RequiredData.CreateParameter("@WorkplaceID",  SqlDbType.VarChar, 50, r["WORKPLACEID"]),
                            _RequiredData.CreateParameter("@TemplateID",   SqlDbType.Int,      0, r["TemplateID"]),
                            // _RequiredData.CreateParameter("@ApprovedBy", SqlDbType.VarChar, 0,TUserInfo.UserID),
                            _RequiredData.CreateParameter("@ActivityType", SqlDbType.Int,      0, r["ActivityType"]),
                            //  _SaveData.CreateParameter("@ApproveItem", SqlDbType.VarChar, 0,"YES"),
                        };

                        _RequiredData.ParamCollection = _paramCollection1;
                        _RequiredData.queryReturnType = MWDataManager.ReturnType.DataTable;
                        _RequiredData.ExecuteInstruction();

                        DataTable dt = new DataTable();
                        dt = _RequiredData.ResultsDataTable;


                        foreach (DataRow dr in dt.Rows)
                        {
                            if (Convert.ToInt32(dr["FIELDCOUNT"]) > 0)
                            {
                                text     += separator + r["DESCRIPTION"];
                                separator = ",";
                                // textCMB += text;

                                string ss = string.Join(",", r["DESCRIPTION"]);
                            }
                            // }
                            else
                            {
                                MWDataManager.clsDataAccess _SaveData = new MWDataManager.clsDataAccess();
                                _SaveData.ConnectionString = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                                // _SaveData.SqlStatement = "spPlanProt_ApproveData";
                                _SaveData.SqlStatement       = "sp_PlanProt_ApproveData";
                                _SaveData.queryExecutionType = MWDataManager.ExecutionType.StoreProcedure;

                                // if (Convert.ToBoolean(r["canApprove"].ToString()) == true)
                                // {

                                SqlParameter[] _paramCollection =
                                {
                                    _SaveData.CreateParameter("@Prodmonth",    SqlDbType.Int,      7, Convert.ToInt32(r["PRODMONTH"].ToString())),
                                    _SaveData.CreateParameter("@SectionID ",   SqlDbType.VarChar, 50, r["SECTIONID"].ToString()),
                                    _SaveData.CreateParameter("@WorkplaceID",  SqlDbType.VarChar, 50, r["WORKPLACEID"]),
                                    _SaveData.CreateParameter("@TemplateID",   SqlDbType.Int,      0, r["TemplateID"]),
                                    _SaveData.CreateParameter("@ApprovedBy",   SqlDbType.VarChar,  0, TUserInfo.UserID),
                                    _SaveData.CreateParameter("@ActivityType", SqlDbType.Int,      0, r["ActivityType"]),
                                    _SaveData.CreateParameter("@ApproveItem",  SqlDbType.VarChar,  0, "YES"),
                                };
                                //foreach (DataRow s in mainData .Rows )
                                //{
                                //    if (s["FieldRe
                                // bool result = false;
                                // var ind = 0;
                                //  DataRow s;
                                foreach (DataRow s in mainData.Rows)
                                {
                                    if (s["WORKPLACEID"].ToString() == r["WORKPLACEID"].ToString())
                                    //else
                                    {
                                        s["Approved"] = "YES";
                                    }
                                }
                                _SaveData.ParamCollection = _paramCollection;
                                _SaveData.queryReturnType = MWDataManager.ReturnType.longNumber;
                                clsDataResult result = _SaveData.ExecuteInstruction();
                                if (result.success == false)
                                {
                                    MessageBox.Show(result.Message);
                                }
                                dt.AcceptChanges();
                                ucPlanProtDataView ucp = new ucPlanProtDataView();
                                ucp.Refresh();
                                ucp.Update();
                                ucp.gridPlanProtData.RefreshData();
                                ucp.gridPlanProtData.Update();
                            }
                        }
                    }
                }
                if (text == ",")
                {
                    MessageBox.Show("Please provide all data required for the Workplaces " + text, "Cannot approve the Workplace", MessageBoxButtons.OK);
                }
                else
                {
                }
                mainData.Select("");
                Close();
            }

            if (theapproveType == "UNAPPROVE")
            {
                MWDataManager.clsDataAccess _SaveData = new MWDataManager.clsDataAccess();
                _SaveData.ConnectionString   = TConnections.GetConnectionString(theSystemDBTag, UserCurrentInfo.Connection);
                _SaveData.SqlStatement       = "sp_PlanProt_ApproveData";
                _SaveData.queryExecutionType = MWDataManager.ExecutionType.StoreProcedure;

                foreach (DataRow r in distinctValuesWorkplace.Rows)
                {
                    if (Convert.ToBoolean(r["canApprove"].ToString()) == true)
                    {
                        SqlParameter[] _paramCollection =
                        {
                            _SaveData.CreateParameter("@Prodmonth",    SqlDbType.Int,      7, Convert.ToInt32(r["PRODMONTH"].ToString())),
                            _SaveData.CreateParameter("@SectionID ",   SqlDbType.VarChar, 50, r["SECTIONID"].ToString()),
                            _SaveData.CreateParameter("@WorkplaceID",  SqlDbType.VarChar, 50, r["WORKPLACEID"]),
                            _SaveData.CreateParameter("@TemplateID",   SqlDbType.Int,      0, r["TemplateID"]),
                            _SaveData.CreateParameter("@ApprovedBy",   SqlDbType.VarChar,  0, TUserInfo.UserID),
                            _SaveData.CreateParameter("@ActivityType", SqlDbType.Int,      0, r["ActivityType"]),
                            _SaveData.CreateParameter("@ApproveItem",  SqlDbType.VarChar,  0, "NO"),
                        };


                        foreach (DataRow s in mainData.Rows)
                        {
                            if (s["WORKPLACEID"].ToString() == r["WORKPLACEID"].ToString())
                            {
                                s["Approved"] = "NO";
                            }
                        }

                        _SaveData.ParamCollection = _paramCollection;
                        _SaveData.queryReturnType = MWDataManager.ReturnType.longNumber;
                        _SaveData.ExecuteInstruction();
                    }
                }
            }


            mainData.Select("");
            Close();
            // }
        }