Esempio n. 1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string   strResult;
            string   strResult1;
            string[] astrFlag = hidFlag.Value.Split('^');
            if (astrFlag[0] == "N")
            {
                astrFlag[1] = "0";
            }
            List <string> lstArray = new List <string>();

            if (astrFlag[0] == "N")
            {
                //  objCCWeb.FillCheckedBoxList(chkReportName, "SELECT 0 AS ReportID,'' AS ReportName" + Session["Type"] + " UNION SELECT ReportID,ReportName" + Session["Type"] + " FROM MTReportMaster WHERE ReportID>0 AND ModuleID="+Convert.ToInt32(ddlModuleID.SelectedValue)+"ORDER BY ReportID, ReportName" + Session["Type"] + "", "ReportID", "ReportName" + Session["Type"] + "", " ");

                if (objCCWeb.ReturnNumericValue("SELECT Count(*) FROM MTReportGroupMaster WHERE ModuleID=" + ddlModuleID.SelectedValue + "") == 5)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language='javascript'>" + strHideID + "alert('Only Five Group Per Module Is Allowed To Create')</script>");
                    return;
                }
                if (objCCWeb.ReturnNumericValue("SELECT COUNT(GroupId) FROM MTReportGroupMaster WHERE UPPER(PriorityNo)='" + txtpriority.Text.Trim() + "' AND GroupId<>" + astrFlag[1] + " AND ModuleID=" + ddlModuleID.SelectedValue) > 0)
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "5", lblpriority.Text);
                    ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language='javascript'>" + strHideID + "alert('" + strResult + "')</script>");
                    txtpriority.Focus();
                    return;
                }


                if (objCCWeb.ReturnNumericValue("SELECT COUNT(GroupId) FROM MTReportGroupMaster WHERE UPPER(GroupName)='" + txtReportGroupName1.Text.Trim().Replace("'", "''").ToUpper() + "' AND GroupId<>" + astrFlag[1]) > 0)
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "5", lblpriority.Text);
                    ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language='javascript'>" + strHideID + "alert('" + strResult + "');</script>");
                    txtReportGroupName1.Focus();
                    return;
                }


                if (objCCWeb.ReturnNumericValue("SELECT COUNT(*) FROM MTReportGroupMaster") == 0)
                {
                    strResult = objCCWeb.ExecuteQuery("INSERT INTO MTReportGroupMaster(GroupID,GroupName,ModuleID,PriorityNo) values(0,'',0,0)");
                }
                strResult = objCCWeb.ExecuteQuery("INSERT INTO MTReportGroupMaster(GroupID,GroupName,ModuleID,PriorityNo) SELECT ISNULL(MAX(GroupID),0)+1,'" + txtReportGroupName1.Text.Trim().Replace("'", "''") + "'," + ddlModuleID.SelectedValue + "," + txtpriority.Text.Trim() + " FROM MTReportGroupMaster ");
                int GroupID = objCCWeb.ReturnNumericValue("SELECT ISNULL(MAX(GroupID),0) FROM MTReportGroupMaster");
                for (int intForLoop = 0; intForLoop < chkReportName.Items.Count; intForLoop++)
                {
                    if (chkReportName.Items[intForLoop].Selected == true)
                    {
                        string[] ReportName  = chkReportName.Items[intForLoop].Text.Split('#');
                        int      INTModuleID = objCCWeb.ReturnNumericValue("SELECT ModuleID FROM MTReportMaster where ReportName" + Session["Type"] + "='" + ReportName[0].Trim() + "'");
                        int      INTReportID = objCCWeb.ReturnNumericValue("SELECT ReportID FROM MTReportMaster where ReportName" + Session["Type"] + "='" + ReportName[0].Trim() + "'");
                        //lstArray.Add("INSERT INTO MTReportGroupMaster(ModuleID) VALUES("+  INTModuleID + ")");
                        lstArray.Add("INSERT INTO MTReportGroupDetails(GroupID,ReportID) Values(" + GroupID + "," + INTReportID + ")");
                    }
                }
                strResult1 = objCCWeb.ExecuteQueryList(lstArray);
            }
            else
            {
                if (astrFlag[0] == "E" && astrFlag[6].Trim() != txtpriority.Text.Trim())
                {
                    //int moduleid = int.Parse(ddlModuleID.SelectedValue);
                    // int i = objCCWeb.ReturnNumericValue("SELECT COUNT(GroupId) FROM MTReportGroupMaster WHERE UPPER(PriorityNo)='" + txtpriority.Text.Trim() + "' AND GroupId<>" + astrFlag[1] + " AND ModuleID=" + ddlModuleID.SelectedValue);
                    if (objCCWeb.ReturnNumericValue("SELECT COUNT(GroupId) FROM MTReportGroupMaster WHERE UPPER(PriorityNo)='" + txtpriority.Text.Trim() + "' AND GroupId<>" + astrFlag[1] + " AND ModuleID=" + astrFlag[5]) > 0)
                    {
                        strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "5", lblpriority.Text);
                        ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language='javascript'>" + strHideID + "alert('" + strResult + "')</script>");
                        hidFlag.Value = "E'" + "^" + "^" + "^" + "^" + "^" + "^";
                        //string str = hidFlag.Value.Split('^');
                        //  str.Replace('E','U');
                        //  hidFlag.Value = str;
                        //string temp="U";
                        //for (int i = 0; i < str.Length; i++)
                        //{
                        //    if (str[i] == 'E')
                        //    {
                        //        temp = temp + str[i];
                        //    }
                        //}

                        //  astrFlag[0].Replace('E','U');
                        //hidFlag.Value = "";
                        txtpriority.Focus();
                        return;
                    }
                }

                if (astrFlag[0] == "E" && astrFlag[2].Trim().ToUpper() != txtReportGroupName1.Text.Trim().ToUpper())
                {
                    if (objCCWeb.ReturnNumericValue("SELECT COUNT(GroupID) FROM MTReportGroupMaster WHERE UPPER(GroupName)='" + txtReportGroupName1.Text.Trim().Replace("'", "''").ToUpper() + "' AND GroupId<>" + astrFlag[1]) > 0)
                    {
                        strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "5", lblReportGroupName1.Text);
                        ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language='javascript'>" + strHideID + "alert('" + strResult + "')</script>");
                        hidFlag.Value = "E'" + "^" + "^" + "^" + "^" + "^" + "^";
                        //hidFlag.Value = "";
                        txtReportGroupName1.Focus();
                        return;
                    }
                }


                //lstArray.Add("DELETE FROM MTReportGroupMaster WHERE GroupID =" + Convert.ToInt32(astrFlag[1]) + "");
                lstArray.Add("DELETE FROM MTReportGroupDetails Where GroupID=" + Convert.ToInt32(astrFlag[1]) + "");
                strResult = objCCWeb.ExecuteQuery("UPDATE MTReportGroupMaster SET GroupName='" + txtReportGroupName1.Text.Trim().Replace("'", "''") + "',ModuleID=" + astrFlag[5] + ",PriorityNo=" + txtpriority.Text.Trim() + "WHERE GroupId=" + Convert.ToInt32(astrFlag[1]) + "");
                int GroupID = objCCWeb.ReturnNumericValue("SELECT ISNULL(MAX(GroupID),0)  FROM MTReportGroupMaster");
                for (int intForLoop = 0; intForLoop < chkReportName.Items.Count; intForLoop++)
                {
                    if (chkReportName.Items[intForLoop].Selected == true)
                    {
                        string[] ReportName = chkReportName.Items[intForLoop].Text.Split('#');

                        int INTModuleID = Convert.ToInt32(ddlModuleID.SelectedValue); //objCCWeb.ReturnNumericValue("SELECT Moduleid FROM MTUserGroupMaster where ModuleName" + Session["Type"] + "='" + ModuleID[0].Trim() + "'");
                        //int INTReportID = objCCWeb.ReturnNumericValue("SELECT ReportID FROM MTReportMaster where ReportName" + Session["Type"] + "='" + ReportName[intForLoop].Trim() + "'");
                        int INTReportID = Convert.ToInt32(chkReportName.Items[intForLoop].Value);
                        //lstArray.Add("INSERT INTO MTReportGroupMaster(GroupID,ModuleID) VALUES(" + Convert.ToInt32(astrFlag[1]) + "," + INTModuleID + ")");
                        lstArray.Add("Insert INTO MTReportGroupDetails(GroupID,ReportID) VALUES(" + Convert.ToInt32(astrFlag[1]) + "," + INTReportID + ")");
                    }
                }
                strResult1 = objCCWeb.ExecuteQueryList(lstArray);
            }
            btnCancel_Click(sender, e);
            //strResult1 = objCCWeb.ExecuteQueryList(lstArray);
            if (strResult == "")
            {
                if (astrFlag[0] == "N")
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "1", "");
                }
                else
                {
                    strResult = objCCWeb.pDisplayMessage("" + Session["Type"].ToString() + "", "2", "");
                }
                ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language=javascript>" + strHideID + "alert('" + strResult + "');</script>");
                objCCWeb.FillCheckedBoxList(chkReportName, "SELECT ReportID,ReportName" + Session["Type"] + " FROM MTReportMaster WHERE ReportID>0 ORDER BY ReportID, ReportName" + Session["Type"] + "", "ReportID", "ReportName" + Session["Type"] + "", "");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "displayScript", "<script language=javascript>" + strHideID + "alert('" + strResult + "')</script>");
            }
            hidFlag.Value = "";
        }
        catch (Exception ex)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "disError", "<script language='javascript'>" + strHideID + "alert('" + ex.Message.ToString().Replace("'", "") + "');</script>");
        }
    }