Esempio n. 1
0
    protected void CreateorUpdateChapter()
    {
        if (BLL_LMS_Training.Check_Duplicate_CHAPTER(txtChapterName.Text, Convert.ToInt32(Request.QueryString["Program_Id"]), UDFLib.ConvertIntegerToNull(ViewState["Chapter_Id"])) == 1)
        {
            string msgmodal = String.Format("alert('Chapter already exists.')");
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "TrainingItem", msgmodal, true);
            return;
        }
        blnChapterItem = false;
        blnTrainer     = false;
        SaveSelectedChapterItems();
        DataTable dtChapterItemList = ViewState["dtChapterItemList"] as DataTable;


        foreach (GridViewRow gr in gvItemList.Rows)
        {
            int Item_ID = Convert.ToInt32(gvItemList.DataKeys[gr.RowIndex].Value);
            if ((gr.FindControl("chkSelected") as CheckBox).Checked == false)
            {
                if (dtChapterItemList.Select("ChapterItemId=" + Item_ID).Length > 0)
                {
                    dtChapterItemList.Rows.Remove(dtChapterItemList.Select("ChapterItemId=" + Item_ID)[0]);
                }
            }
        }


        DataTable dtChapterTrainerList = new DataTable();

        dtChapterTrainerList.Columns.Add("ChapterTrainerId", typeof(int));
        DataRow dr_Trainer;

        foreach (GridViewRow gr in gvTrainerRank.Rows)
        {
            dr_Trainer = dtChapterTrainerList.NewRow();
            bool Checked = (gr.FindControl("chkSelected") as CheckBox).Checked;
            if (Checked)
            {
                blnTrainer = true;
                dr_Trainer["ChapterTrainerId"] = Convert.ToInt32(gvTrainerRank.DataKeys[gr.RowIndex].Value);
                dtChapterTrainerList.Rows.Add(dr_Trainer);
            }
        }
        if (dtChapterItemList != null)
        {
            if (dtChapterItemList.Rows.Count > 0)
            {
                blnChapterItem = true;
            }
        }
        if (blnChapterItem == false)
        {
            string msgmodal = String.Format("alert('Please select at least One chapter Item.')");
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "TrainingItem", msgmodal, true);
            return;
        }



        if (BLL_LMS_Training.Check_Chapter_Item(UDFLib.ConvertIntegerToNull(Request.QueryString["Program_Id"]), UDFLib.ConvertIntegerToNull(ViewState["Chapter_Id"]), dtChapterItemList) == 1)
        {
            string msgmodal = String.Format("alert('Chapter items already exist in this program.')");
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "TrainingItem", msgmodal, true);
            return;
        }



        if (blnTrainer == false && UDFLib.ConvertIntegerToNull(Request.QueryString["ProgramCategory"]) != 4)
        {
            string msgmodal = String.Format("alert('Please select at least one Trainer.')");
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "TrainingItem", msgmodal, true);
            return;
        }
        int?      Chapter_Id        = UDFLib.ConvertToInteger(ViewState["Chapter_Id"]);
        DataTable ChapterItemExists = BLL_LMS_Training.Ins_Chapter_Details(UDFLib.ConvertIntegerToNull(Request.QueryString["Program_Id"]), txtChapterName.Text.Trim(), ref Chapter_Id, txtChapterName.Text, dtChapterItemList, dtChapterTrainerList, Convert.ToInt32(Session["USERID"]), 1);



        if (Chapter_Id != 0)
        {
            ViewState["Chapter_Id"] = Chapter_Id;
        }

        Boolean blnchk = false;

        foreach (GridViewRow row in gvItemList.Rows)
        {
            foreach (DataRow dr in ChapterItemExists.Rows)
            {
                if (UDFLib.ConvertIntegerToNull(dr["ITEM_ID"]) == Convert.ToInt32(gvItemList.DataKeys[row.RowIndex].Values[0]))
                {
                    row.BackColor = System.Drawing.Color.Red;
                    blnchk        = true;
                }
            }
        }
        string js;

        if (blnchk == true)
        {
            js = String.Format("parent.ReloadParent_ByButtonID();");
            ScriptManager.RegisterStartupScript(this, this.GetType(), "ReloadParent", js, true);
            return;
        }

        js = String.Format("parent.ReloadParent_ByButtonID();");
        ScriptManager.RegisterStartupScript(this, this.GetType(), "ReloadParent", js, true);
    }