protected void FillControl()
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List <SelectedCollborators_Details>         lstSelCollab = new List <SelectedCollborators_Details>();
            List <Selected_Clause_Details>              lstSelClause = new List <Selected_Clause_Details>();
            List <ContractDetails_MultipleContractFile> lstmultiple  = new List <ContractDetails_MultipleContractFile>();
            List <PI_Master> piList = new List <PI_Master>();
            List <Contract_Collobrator_Master> ccdlist = new List <Contract_Collobrator_Master>();
            List <Project_Master> pjmasterlist         = new List <Project_Master>();
            Contract_Details      _Contract_Details    = new Contract_Details();
            List <ContractList>   ctlist = new List <ContractList>();

            try
            {
                _Contract_Details = cl.GetContract_DetailsDetailsByID(Convert.ToInt32(HdnProjectId.Value));


                //****************Contact*******************
                RptContract.DataSource = null; RptContract.DataBind();
                if (_Contract_Details.contlist != null)
                {
                    ctlist = _Contract_Details.contlist.ToList();
                    RptContract.DataSource = ctlist;
                    RptContract.DataBind();
                }

                //***************END**********************

                //************Selected Collaborator*************
                chkCollaboratorList.FillCheckList(DropDownName.FillCollaborators, HdnProjectId.Value);
                //**************END*******************************
            }
            catch (Exception)
            {
            }
        }
        protected bool SaveFinalContract()
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List<SelectedCollborators_Details> lstSelCollab = new List<SelectedCollborators_Details>();
            List<Selected_Clause_Details> lstSelClause = new List<Selected_Clause_Details>();
            List<ContractDetails_MultipleContractFile> lstmultiple = new List<ContractDetails_MultipleContractFile>();
            Contract_Details cd = new Contract_Details();
            SelectedCollborators_Details scd = new SelectedCollborators_Details();
            Selected_Clause_Details selcd = new Selected_Clause_Details();
            ContractDetails_MultipleContractFile cdm = new ContractDetails_MultipleContractFile();
            string result = "";

            try
            {
                cd.i_ID = Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0));
                cd.s_Contract_Display_Id = Convert.ToString(Common.iffBlank(TxtContractId.Text, ""));
                cd.s_Contract_Name = Convert.ToString(Common.iffBlank(TxtContractName.Text, ""));
                cd.i_Project_ID = Convert.ToInt32(HdnProjectId.Value);
                cd.i_Contract_Category_ID = Convert.ToInt32(Common.iffBlank(ddlContractCategory.SelectedValue, 0));
                cd.i_Contract_Status_ID = Convert.ToInt32(Common.iffBlank(ddlContractStatus.SelectedValue, 0));
                cd.dt_Contract_StatusDate = TxtContStartDate.Text == "" ? null : TxtContStartDate.Text;
                cd.i_Govt_Lawcountry = Convert.ToInt32(Common.iffBlank(HdnGovCountry.Value, 0));
                cd.dt_LastUpdated_Date = TxtLastDate.Text == "" ? null : TxtLastDate.Text;
                cd.s_Clauses_File = Convert.ToString(Common.iffBlank((fldCorespondace.HasFile) ? String.Join(",", Common.UpLoadNew(fldCorespondace, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())) : hdnCoresPath.Value, ""));
                if (hdnCoresPath.Value.Length > 0)
                {
                    cd.s_Clauses_File = (cd.s_Clauses_File != "") ? cd.s_Clauses_File : hdnCoresPath.Value;
                }
                cd.i_Hospital_Cost = Convert.ToDouble(Common.iffBlank(TxtprocedureCost.Text, 0));
                cd.i_Investigator_fees = Convert.ToDouble(Common.iffBlank(TxtInvestigatorFees.Text, 0));
                cd.i_Coordinator_fess = Convert.ToDouble(Common.iffBlank(TxtCoOrdinatorFess.Text, 0));

                string[] arr = String.Join(",", chkCollaboratorList.Items.OfType<ListItem>().Where(r => r.Selected).Select(r => r.Value)).Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    lstSelCollab.Add(new SelectedCollborators_Details
                    {
                        i_Contract_Details_Id = 0,
                        i_Collobrator_ID = Convert.ToInt32(arr[i])
                    });
                }
                string[] ClausesVal = HdnClauseValues.Value.ToString().Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int j = 0; j < ClausesVal.Length; j++)
                {
                    lstSelClause.Add(new Selected_Clause_Details
                    {
                        i_Contract_ID = 0,
                        i_Contract_Clause_ID = Convert.ToInt32(Common.iffBlank(ClausesVal[j].Split('|')[0], 0)),
                        s_Status = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[1], "")),
                        s_Comments = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[3], "")),
                        s_Proposed_Changes = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[4], "")),
                    });
                }
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {
                    cd.dt_Effective_Date = TxtEffectiveDate.Text == "" ? null : TxtEffectiveDate.Text;
                    cd.dt_Expiry_Date = TxtContractExpDate.Text == "" ? null : TxtContractExpDate.Text;
                    cd.dt_Finalization_Date = TxtContractFinalizeDate.Text == "" ? null : TxtContractFinalizeDate.Text;
                    cd.dt_LastSigned_Date = TxtDateofLast.Text == "" ? null : TxtDateofLast.Text;

                    if (fldContractFile.HasFiles)
                    {
                        string[] multipleFiles = String.Join(",", Common.UpLoadNew(fldContractFile, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())).Split(',');
                        for (int k = 0; k < multipleFiles.Length; k++)
                        {
                            lstmultiple.Add(new ContractDetails_MultipleContractFile
                            {
                                i_ContractDetailsID = 0,
                                s_ContractFile = Convert.ToString(Common.iffBlank(multipleFiles[k], ""))
                            });
                        }
                    }
                    if (HdnContractFiles.Value.Length > 0)
                    {
                        string[] files = HdnContractFiles.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < files.Length; i++)
                        {
                            lstmultiple.Add(new ContractDetails_MultipleContractFile
                            {
                                i_ContractDetailsID = 0,
                                s_ContractFile = Convert.ToString(Common.iffBlank(files[i], ""))
                            });

                        }
                    }

                    if (ddlAmendments.SelectedItem.Text.ToLower() == "yes")
                    {
                        cd.b_Amendments = Convert.ToInt32(Common.iffBlank(ddlAmendments.SelectedItem.Value, 0)) == 1 ? true : false;

                        cd.dt_NewExpiry_Date = Convert.ToString(Common.iffBlank(TxtNContractExpiryDate.Text, ""));
                        cd.s_AmendmenstContract_File = Convert.ToString(Common.iffBlank((fldAmendmentFile.HasFile) ? String.Join(",", Common.UpLoadNew(fldAmendmentFile, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())) : HdnAmendPath.Value, ""));
                        if (HdnAmendPath.Value.Length > 0)
                        {
                            cd.s_AmendmenstContract_File = (cd.s_AmendmenstContract_File != "") ? cd.s_AmendmenstContract_File : HdnAmendPath.Value;
                        }

                    }

                }

                //--------UID and UName----
                cd.UName = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserName"]), "").ToString();
                cd.UID = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserID"]), "").ToString();
                //----------- END ------------

                result = cl.Contract_Details_DML(cd, lstSelCollab.ToArray(), lstSelClause.ToArray(), lstmultiple.ToArray(), HdnContractMode.Value);

                //}
                if (result.Split('|')[0].ToLower().Trim() == "success" && result.Split('|')[1].ToLower().CheckInt() == true)
                {

                    switch (HdnContractMode.Value.ToLower())
                    {
                        case "update": this.PopUpMsg("Contract Detail Update  Successfully..!!", "AfterSave();"); break;
                        case "delete": this.PopUpMsg("Contract Detail Delete  Successfully..!!", "AfterSave();"); break;
                        case "insert": this.PopUpMsg("Contract Detail Save  Successfully..!!", "AfterSave();"); break;

                    }
                    btnResets_Click(null, null);
                    btnContractSave.Text = "Save";
                    HdnContractId.Value = result.Split('|')[1];
                    //ClearContractControlAfterSave();
                    FillControl();
                }
                else
                {
                    this.MsgBox(result.Split('|')[1]);
                    return false;
                }
            }
            //}

                //}
            catch (Exception ex)
            {
                this.MsgBox(ex.Message);
                return false;
            }
            return true;
        }
        protected void FillControl()
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List<SelectedCollborators_Details> lstSelCollab = new List<SelectedCollborators_Details>();
            List<Selected_Clause_Details> lstSelClause = new List<Selected_Clause_Details>();
            List<ContractDetails_MultipleContractFile> lstmultiple = new List<ContractDetails_MultipleContractFile>();
            List<PI_Master> piList = new List<PI_Master>();
            List<Contract_Collobrator_Master> ccdlist = new List<Contract_Collobrator_Master>();
            List<Project_Master> pjmasterlist = new List<Project_Master>();
            Contract_Details _Contract_Details = new Contract_Details();
            List<ContractList> ctlist = new List<ContractList>();
            try
            {
                _Contract_Details = cl.GetContract_DetailsDetailsByID(Convert.ToInt32(HdnProjectId.Value));

                //****************Contact*******************
                RptContract.DataSource = null; RptContract.DataBind();
                if (_Contract_Details.contlist != null)
                {
                    ctlist = _Contract_Details.contlist.ToList();
                    RptContract.DataSource = ctlist;
                    RptContract.DataBind();
                }

                //***************END**********************

                //************Selected Collaborator*************
                chkCollaboratorList.FillCheckList(DropDownName.FillCollaborators, HdnProjectId.Value);
                //**************END*******************************
            }
            catch (Exception)
            {

            }
        }
        protected void FillContractDetail(string mode = "Save", int ProjectId = 0)
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List<SelectedCollborators_Details> lstSelCollab = new List<SelectedCollborators_Details>();
            List<Selected_Clause_Details> lstSelClause = new List<Selected_Clause_Details>();
            List<ContractDetails_MultipleContractFile> lstmultiple = new List<ContractDetails_MultipleContractFile>();
            Contract_Details _Contract_Details = new Contract_Details();
            List<ContractList> ctlist = new List<ContractList>();
            List<Contract_Status_Date> lstcsd = new List<Contract_Status_Date>();
            try
            {
                _Contract_Details = cl.GetContractDeta(Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0)), ProjectId);

                ////****************Contact*******************
                //ctlist = _Contract_Details.contlist.ToList();
                //RptContract.DataSource = ctlist;
                //RptContract.DataBind();
                ////***************END**********************

                //if (Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0)) > 0)
                //{

                //************Selected Collaborator*************
                chkCollaboratorList.FillCheckList(DropDownName.FillCollaborators, HdnProjectId.Value);
                lstSelCollab = _Contract_Details.lstSelCollab.ToList();
                if (chkCollaboratorList.Items.Count > 0)
                {
                    for (int i = 0; i < lstSelCollab.ListToDatatable().Rows.Count; i++)
                    {
                        chkCollaboratorList.Items.Add(new ListItem() { Value = Convert.ToString(lstSelCollab.ListToDatatable().Rows[i]["i_Collobrator_ID"]), Text = Convert.ToString(lstSelCollab.ListToDatatable().Rows[i]["s_Name"]), Selected = true });
                    }

                }
                else
                {
                    chkCollaboratorList.DataSource = lstSelCollab;
                    chkCollaboratorList.DataTextField = "s_Name";
                    chkCollaboratorList.DataValueField = "i_Collobrator_ID";
                    chkCollaboratorList.DataBind();
                    foreach (ListItem item in chkCollaboratorList.Items)
                    {
                        item.Selected = true;
                    }
                }

                //var id = (from i in lstSelCollab select new { i.i_Collobrator_ID }).ToList().ListToDatatable();

                //for (int i = 0; i < id.Rows.Count; i++)
                //{
                //    for (int j = 0; j < chkCollaboratorList.Items.Count; j++)
                //    {
                //        if (chkCollaboratorList.Items[j].Value == Convert.ToString(id.Rows[i]["i_Collobrator_ID"]))
                //        {
                //            chkCollaboratorList.Items[j].Selected = true;
                //        }
                //    }
                //}
                //**************END*******************************

                //***********************Selected Clauese***************
                lstSelClause = _Contract_Details.lstSelClause.ToList();
                RptClauseDetail.DataSource = lstSelClause; RptClauseDetail.DataBind();

                //**************************END************************

                TxtContractName.Text = _Contract_Details.s_Contract_Name;
                TxtContractId.Text = _Contract_Details.s_Contract_Display_Id;
                FillCombo();
                ddlContractCategory.SelectedIndex = ddlContractCategory.Items.IndexOf(ddlContractCategory.Items.FindByValue(_Contract_Details.i_Contract_Category_ID.ToString()));
                ddlContractStatus.SelectedIndex = ddlContractStatus.Items.IndexOf(ddlContractStatus.Items.FindByValue(_Contract_Details.i_Contract_Status_ID.ToString()));
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "terminated/withdrawn" || ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "showMsg", "javascript:DisableOnCompletedStatus();", true);

                }
                lstcsd = _Contract_Details.listcsd.ToList();
                DataRow[] dr = lstcsd.ListToDatatable().Select("i_Contract_Status_ID=" + ddlContractStatus.SelectedValue);
                TxtContStartDate.Text = (dr.Length > 0) ? Convert.ToString(dr[0].ItemArray[1]) : "";
                FillClausesCheckList();
                var q = (from i in lstSelClause select new { i.Clause_Name, i.i_Contract_Clause_ID }).ToList().ListToDatatable();
                string arrvalue = string.Join(",", q.AsEnumerable().Select(i => i.Field<int>("i_Contract_Clause_ID")).ToArray());
                for (int j = 0; j < q.Rows.Count; j++)
                {

                    for (int i = 0; i < chkClause.Items.Count; i++)
                    {
                        if (chkClause.Items[i].Value == Convert.ToString(q.Rows[j]["i_Contract_Clause_ID"]))
                        {
                            chkClause.Items[i].Selected = true;

                        }
                    }
                }
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "showMsg", "javascript:PushValues('" + arrvalue + "')", true);
                TxtGovCountry.Text = _Contract_Details.s_Country;
                HdnGovCountry.Value = Convert.ToString(_Contract_Details.i_Govt_Lawcountry);

                //***************Corrrespondance File*******************
                hdnCoresPath.Value = _Contract_Details.s_Clauses_File;
                lnkDwnldCorespondace.Text = _Contract_Details.s_Clauses_File.GetFileName();
                //*************END*********************
                TxtLastDate.Text = _Contract_Details.dt_LastUpdated_Date;
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {

                    //************Multiple Contract File************
                    lstmultiple = _Contract_Details.lstmultiple.ToList();
                    var h = (from k in lstmultiple select new { k.s_ContractFile }).ToList().ListToDatatable();

                    if (h != null)
                    {

                        for (int i = 0; i < h.Rows.Count; i++)
                        {

                            HiddenField hdn = new HiddenField();
                            LinkButton lnk = new LinkButton();
                            HtmlGenericControl div = new HtmlGenericControl("div"); HtmlGenericControl a = new HtmlGenericControl("a");
                            lnk.ID = "lnk" + i.ToString();
                            hdn.Value = Convert.ToString(h.Rows[i][0]);
                            hdn.ID = "hdn" + i.ToString();
                            a.ID = "a~" + i.ToString();
                            lnk.Text = h.Rows[i][0].ToString().GetFileName();
                            a.InnerText = "X";

                            lnk.OnClientClick = "return Callhandler('" + ResolveUrl("~/DownloadHandler.ashx") + "','" + hdn.Value + "')";

                            div.Attributes.Add("class", "MultiFile-label");
                            a.Attributes.Add("class", "MultiFile-remove");
                            a.Style["margin-right"] = "5px";
                            a.Attributes.Add("onclick", "return RemoveDownloadFile(this)");
                            lnk.Attributes.Add("class", "MultiFile-title");
                            div.Controls.Add(a);
                            div.Controls.Add(lnk);
                            div.Controls.Add(hdn);
                            multilistdiv.Controls.Add(div);

                        }

                    }

                    TxtContractExpDate.Text = _Contract_Details.dt_Expiry_Date;
                    HdnContExpDate.Value = _Contract_Details.dt_Expiry_Date;
                    TxtEffectiveDate.Text = _Contract_Details.dt_Effective_Date;
                    TxtDateofLast.Text = _Contract_Details.dt_LastSigned_Date;
                    TxtContractFinalizeDate.Text = _Contract_Details.dt_Finalization_Date;

                    ddlAmendments.SelectedIndex = (_Contract_Details.b_Amendments == true) ? 1 : 0;
                    if (ddlAmendments.SelectedIndex == 1)
                    {

                        TxtNContractExpiryDate.Text = _Contract_Details.dt_NewExpiry_Date;
                        //**************Amendments File******************
                        HdnAmendPath.Value = _Contract_Details.s_AmendmenstContract_File;
                        lnkDwnldAmendment.Text = _Contract_Details.s_AmendmenstContract_File.GetFileName();
                        //***************END*****************************
                    }
                }
                //*****************END************************
                TxtprocedureCost.Text = (_Contract_Details.i_Hospital_Cost == 0) ? "" : Convert.ToString(_Contract_Details.i_Hospital_Cost);
                TxtInvestigatorFees.Text = (_Contract_Details.i_Investigator_fees == 0) ? "" : Convert.ToString(_Contract_Details.i_Investigator_fees);
                TxtCoOrdinatorFess.Text = (_Contract_Details.i_Coordinator_fess == 0) ? "" : Convert.ToString(_Contract_Details.i_Coordinator_fess);
                TxtProjectBudgetCash.Text = Convert.ToString(Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Hospital_Cost, 0)) +
                                                                Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Investigator_fees, 0)) +
                                                                Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Coordinator_fess, 0)));
                if (TxtProjectBudgetCash.Text == "0")
                {
                    TxtProjectBudgetCash.Text = "";
                }

                btnContractSave.Visible = true;

                if (mode.ToLower() == "view")
                {
                    PNewCollaborator.Style["display"] = "none";
                    //  btnCReset.Style["display"] = "block";
                    btnContractCancel.Style["display"] = "none";
                    btnContractSave.Style["display"] = "none";
                    h3.Style["display"] = "none";
                    LinkButton2.Style["display"] = "block";

                }
                if (mode.ToLower() == "delete")
                {
                    btnCReset.Style["display"] = "none";
                    btnContractSave.Style["display"] = "block";
                    btnContractCancel.Style["display"] = "block";
                    btnContractSave.Text = mode;
                }
                else
                {
                    btnContractSave.Text = mode;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Contract_Details cd = new Contract_Details();

            SearchBox.SearchFilterCriteria = TTSHWeb.SearchBox.FilterCriteria.SELECTED; /*setting filtercriteria*/
            SearchBox.ButtonSearchClick += new EventHandler(SearchBox_ButtonClick); /*adding events*/
            SearchBox.ButtonClearClick += new EventHandler(SearchBox_ClearClick); /*adding events*/
            //Code to assign user id ,user name and user groups

            if (HttpContext.Current.Session["UserGroups"] != null)
            {
                if (HttpContext.Current.Session["UserGroups"].ToString().Contains("TProjectMonitoring"))
                {
                    isSelectedTeamUser = true;
                }
                else if (HttpContext.Current.Session["UserGroups"].ToString().Contains("TAdmin"))
                {
                    isSelectedTeamUser = true;
                    //isBlindedUser = true;
                    //isUnblinded = true;

                }
                else
                {

                }
            }

            //==Temp Code
            //isSelectedTeamUser = true;
            //LoginUserId = "5911B068-5137-4DC1-BEAE-BF6C74E4FD00";

            if (HttpContext.Current.Session["UserName"] != null)
            {
                LoginUser = HttpContext.Current.Session["UserName"].ToString();

            }
            if (HttpContext.Current.Session["UserID"] != null)
            {
                LoginUserId = HttpContext.Current.Session["UserID"].ToString();

            }

            if (!IsPostBack)
            {
                TextBox t = ((TextBox)(SearchBox.FindControl("txtSearch")));
                t.Text = "";
                FillGrid();

            }
        }
        protected void FillContractDetail(string mode = "Save", int ProjectId = 0)
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List <SelectedCollborators_Details>         lstSelCollab = new List <SelectedCollborators_Details>();
            List <Selected_Clause_Details>              lstSelClause = new List <Selected_Clause_Details>();
            List <ContractDetails_MultipleContractFile> lstmultiple  = new List <ContractDetails_MultipleContractFile>();
            Contract_Details            _Contract_Details            = new Contract_Details();
            List <ContractList>         ctlist = new List <ContractList>();
            List <Contract_Status_Date> lstcsd = new List <Contract_Status_Date>();

            try
            {
                _Contract_Details = cl.GetContractDeta(Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0)), ProjectId);

                ////****************Contact*******************
                //ctlist = _Contract_Details.contlist.ToList();
                //RptContract.DataSource = ctlist;
                //RptContract.DataBind();
                ////***************END**********************



                //if (Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0)) > 0)
                //{


                //************Selected Collaborator*************
                chkCollaboratorList.FillCheckList(DropDownName.FillCollaborators, HdnProjectId.Value);
                lstSelCollab = _Contract_Details.lstSelCollab.ToList();
                if (chkCollaboratorList.Items.Count > 0)
                {
                    for (int i = 0; i < lstSelCollab.ListToDatatable().Rows.Count; i++)
                    {
                        chkCollaboratorList.Items.Add(new ListItem()
                        {
                            Value = Convert.ToString(lstSelCollab.ListToDatatable().Rows[i]["i_Collobrator_ID"]), Text = Convert.ToString(lstSelCollab.ListToDatatable().Rows[i]["s_Name"]), Selected = true
                        });
                    }
                }
                else
                {
                    chkCollaboratorList.DataSource     = lstSelCollab;
                    chkCollaboratorList.DataTextField  = "s_Name";
                    chkCollaboratorList.DataValueField = "i_Collobrator_ID";
                    chkCollaboratorList.DataBind();
                    foreach (ListItem item in chkCollaboratorList.Items)
                    {
                        item.Selected = true;
                    }
                }

                //var id = (from i in lstSelCollab select new { i.i_Collobrator_ID }).ToList().ListToDatatable();

                //for (int i = 0; i < id.Rows.Count; i++)
                //{
                //    for (int j = 0; j < chkCollaboratorList.Items.Count; j++)
                //    {
                //        if (chkCollaboratorList.Items[j].Value == Convert.ToString(id.Rows[i]["i_Collobrator_ID"]))
                //        {
                //            chkCollaboratorList.Items[j].Selected = true;
                //        }
                //    }
                //}
                //**************END*******************************

                //***********************Selected Clauese***************
                lstSelClause = _Contract_Details.lstSelClause.ToList();
                RptClauseDetail.DataSource = lstSelClause; RptClauseDetail.DataBind();

                //**************************END************************



                TxtContractName.Text = _Contract_Details.s_Contract_Name;
                TxtContractId.Text   = _Contract_Details.s_Contract_Display_Id;
                FillCombo();
                ddlContractCategory.SelectedIndex = ddlContractCategory.Items.IndexOf(ddlContractCategory.Items.FindByValue(_Contract_Details.i_Contract_Category_ID.ToString()));
                ddlContractStatus.SelectedIndex   = ddlContractStatus.Items.IndexOf(ddlContractStatus.Items.FindByValue(_Contract_Details.i_Contract_Status_ID.ToString()));
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "terminated/withdrawn" || ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "showMsg", "javascript:DisableOnCompletedStatus();", true);
                }
                lstcsd = _Contract_Details.listcsd.ToList();
                DataRow[] dr = lstcsd.ListToDatatable().Select("i_Contract_Status_ID=" + ddlContractStatus.SelectedValue);
                TxtContStartDate.Text = (dr.Length > 0) ? Convert.ToString(dr[0].ItemArray[1]) : "";
                FillClausesCheckList();
                var    q        = (from i in lstSelClause select new { i.Clause_Name, i.i_Contract_Clause_ID }).ToList().ListToDatatable();
                string arrvalue = string.Join(",", q.AsEnumerable().Select(i => i.Field <int>("i_Contract_Clause_ID")).ToArray());
                for (int j = 0; j < q.Rows.Count; j++)
                {
                    for (int i = 0; i < chkClause.Items.Count; i++)
                    {
                        if (chkClause.Items[i].Value == Convert.ToString(q.Rows[j]["i_Contract_Clause_ID"]))
                        {
                            chkClause.Items[i].Selected = true;
                        }
                    }
                }
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "showMsg", "javascript:PushValues('" + arrvalue + "')", true);
                TxtGovCountry.Text  = _Contract_Details.s_Country;
                HdnGovCountry.Value = Convert.ToString(_Contract_Details.i_Govt_Lawcountry);

                //***************Corrrespondance File*******************
                hdnCoresPath.Value        = _Contract_Details.s_Clauses_File;
                lnkDwnldCorespondace.Text = _Contract_Details.s_Clauses_File.GetFileName();
                //*************END*********************
                TxtLastDate.Text = _Contract_Details.dt_LastUpdated_Date;
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {
                    //************Multiple Contract File************
                    lstmultiple = _Contract_Details.lstmultiple.ToList();
                    var h = (from k in lstmultiple select new { k.s_ContractFile }).ToList().ListToDatatable();

                    if (h != null)
                    {
                        for (int i = 0; i < h.Rows.Count; i++)
                        {
                            HiddenField        hdn = new HiddenField();
                            LinkButton         lnk = new LinkButton();
                            HtmlGenericControl div = new HtmlGenericControl("div"); HtmlGenericControl a = new HtmlGenericControl("a");
                            lnk.ID      = "lnk" + i.ToString();
                            hdn.Value   = Convert.ToString(h.Rows[i][0]);
                            hdn.ID      = "hdn" + i.ToString();
                            a.ID        = "a~" + i.ToString();
                            lnk.Text    = h.Rows[i][0].ToString().GetFileName();
                            a.InnerText = "X";

                            lnk.OnClientClick = "return Callhandler('" + ResolveUrl("~/DownloadHandler.ashx") + "','" + hdn.Value + "')";

                            div.Attributes.Add("class", "MultiFile-label");
                            a.Attributes.Add("class", "MultiFile-remove");
                            a.Style["margin-right"] = "5px";
                            a.Attributes.Add("onclick", "return RemoveDownloadFile(this)");
                            lnk.Attributes.Add("class", "MultiFile-title");
                            div.Controls.Add(a);
                            div.Controls.Add(lnk);
                            div.Controls.Add(hdn);
                            multilistdiv.Controls.Add(div);
                        }
                    }



                    TxtContractExpDate.Text      = _Contract_Details.dt_Expiry_Date;
                    HdnContExpDate.Value         = _Contract_Details.dt_Expiry_Date;
                    TxtEffectiveDate.Text        = _Contract_Details.dt_Effective_Date;
                    TxtDateofLast.Text           = _Contract_Details.dt_LastSigned_Date;
                    TxtContractFinalizeDate.Text = _Contract_Details.dt_Finalization_Date;



                    ddlAmendments.SelectedIndex = (_Contract_Details.b_Amendments == true) ? 1 : 0;
                    if (ddlAmendments.SelectedIndex == 1)
                    {
                        TxtNContractExpiryDate.Text = _Contract_Details.dt_NewExpiry_Date;
                        //**************Amendments File******************
                        HdnAmendPath.Value     = _Contract_Details.s_AmendmenstContract_File;
                        lnkDwnldAmendment.Text = _Contract_Details.s_AmendmenstContract_File.GetFileName();
                        //***************END*****************************
                    }
                }
                //*****************END************************
                TxtprocedureCost.Text     = (_Contract_Details.i_Hospital_Cost == 0) ? "" : Convert.ToString(_Contract_Details.i_Hospital_Cost);
                TxtInvestigatorFees.Text  = (_Contract_Details.i_Investigator_fees == 0) ? "" : Convert.ToString(_Contract_Details.i_Investigator_fees);
                TxtCoOrdinatorFess.Text   = (_Contract_Details.i_Coordinator_fess == 0) ? "" : Convert.ToString(_Contract_Details.i_Coordinator_fess);
                TxtProjectBudgetCash.Text = Convert.ToString(Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Hospital_Cost, 0)) +
                                                             Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Investigator_fees, 0)) +
                                                             Convert.ToInt32(Common.iffBlank(_Contract_Details.i_Coordinator_fess, 0)));
                if (TxtProjectBudgetCash.Text == "0")
                {
                    TxtProjectBudgetCash.Text = "";
                }

                btnContractSave.Visible = true;

                if (mode.ToLower() == "view")
                {
                    PNewCollaborator.Style["display"] = "none";
                    //  btnCReset.Style["display"] = "block";
                    btnContractCancel.Style["display"] = "none";
                    btnContractSave.Style["display"]   = "none";
                    h3.Style["display"]          = "none";
                    LinkButton2.Style["display"] = "block";
                }
                if (mode.ToLower() == "delete")
                {
                    btnCReset.Style["display"]         = "none";
                    btnContractSave.Style["display"]   = "block";
                    btnContractCancel.Style["display"] = "block";
                    btnContractSave.Text = mode;
                }
                else
                {
                    btnContractSave.Text = mode;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        protected bool SaveFinalContract()
        {
            TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            List <SelectedCollborators_Details>         lstSelCollab = new List <SelectedCollborators_Details>();
            List <Selected_Clause_Details>              lstSelClause = new List <Selected_Clause_Details>();
            List <ContractDetails_MultipleContractFile> lstmultiple  = new List <ContractDetails_MultipleContractFile>();
            Contract_Details                     cd    = new Contract_Details();
            SelectedCollborators_Details         scd   = new SelectedCollborators_Details();
            Selected_Clause_Details              selcd = new Selected_Clause_Details();
            ContractDetails_MultipleContractFile cdm   = new ContractDetails_MultipleContractFile();
            string result = "";

            try
            {
                cd.i_ID = Convert.ToInt32(Common.iffBlank(HdnContractId.Value, 0));
                cd.s_Contract_Display_Id  = Convert.ToString(Common.iffBlank(TxtContractId.Text, ""));
                cd.s_Contract_Name        = Convert.ToString(Common.iffBlank(TxtContractName.Text, ""));
                cd.i_Project_ID           = Convert.ToInt32(HdnProjectId.Value);
                cd.i_Contract_Category_ID = Convert.ToInt32(Common.iffBlank(ddlContractCategory.SelectedValue, 0));
                cd.i_Contract_Status_ID   = Convert.ToInt32(Common.iffBlank(ddlContractStatus.SelectedValue, 0));
                cd.dt_Contract_StatusDate = TxtContStartDate.Text == "" ? null : TxtContStartDate.Text;
                cd.i_Govt_Lawcountry      = Convert.ToInt32(Common.iffBlank(HdnGovCountry.Value, 0));
                cd.dt_LastUpdated_Date    = TxtLastDate.Text == "" ? null : TxtLastDate.Text;
                cd.s_Clauses_File         = Convert.ToString(Common.iffBlank((fldCorespondace.HasFile) ? String.Join(",", Common.UpLoadNew(fldCorespondace, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())) : hdnCoresPath.Value, ""));
                if (hdnCoresPath.Value.Length > 0)
                {
                    cd.s_Clauses_File = (cd.s_Clauses_File != "") ? cd.s_Clauses_File : hdnCoresPath.Value;
                }
                cd.i_Hospital_Cost     = Convert.ToDouble(Common.iffBlank(TxtprocedureCost.Text, 0));
                cd.i_Investigator_fees = Convert.ToDouble(Common.iffBlank(TxtInvestigatorFees.Text, 0));
                cd.i_Coordinator_fess  = Convert.ToDouble(Common.iffBlank(TxtCoOrdinatorFess.Text, 0));

                string[] arr = String.Join(",", chkCollaboratorList.Items.OfType <ListItem>().Where(r => r.Selected).Select(r => r.Value)).Split(',');
                for (int i = 0; i < arr.Length; i++)
                {
                    lstSelCollab.Add(new SelectedCollborators_Details
                    {
                        i_Contract_Details_Id = 0,
                        i_Collobrator_ID      = Convert.ToInt32(arr[i])
                    });
                }
                string[] ClausesVal = HdnClauseValues.Value.ToString().Split(new char[] { '~' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int j = 0; j < ClausesVal.Length; j++)
                {
                    lstSelClause.Add(new Selected_Clause_Details
                    {
                        i_Contract_ID        = 0,
                        i_Contract_Clause_ID = Convert.ToInt32(Common.iffBlank(ClausesVal[j].Split('|')[0], 0)),
                        s_Status             = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[1], "")),
                        s_Comments           = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[3], "")),
                        s_Proposed_Changes   = Convert.ToString(Common.iffBlank(ClausesVal[j].Split('|')[4], "")),
                    });
                }
                if (ddlContractStatus.SelectedItem.Text.ToLower() == "completed")
                {
                    cd.dt_Effective_Date    = TxtEffectiveDate.Text == "" ? null : TxtEffectiveDate.Text;
                    cd.dt_Expiry_Date       = TxtContractExpDate.Text == "" ? null : TxtContractExpDate.Text;
                    cd.dt_Finalization_Date = TxtContractFinalizeDate.Text == "" ? null : TxtContractFinalizeDate.Text;
                    cd.dt_LastSigned_Date   = TxtDateofLast.Text == "" ? null : TxtDateofLast.Text;


                    if (fldContractFile.HasFiles)
                    {
                        string[] multipleFiles = String.Join(",", Common.UpLoadNew(fldContractFile, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())).Split(',');
                        for (int k = 0; k < multipleFiles.Length; k++)
                        {
                            lstmultiple.Add(new ContractDetails_MultipleContractFile
                            {
                                i_ContractDetailsID = 0,
                                s_ContractFile      = Convert.ToString(Common.iffBlank(multipleFiles[k], ""))
                            });
                        }
                    }
                    if (HdnContractFiles.Value.Length > 0)
                    {
                        string[] files = HdnContractFiles.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < files.Length; i++)
                        {
                            lstmultiple.Add(new ContractDetails_MultipleContractFile
                            {
                                i_ContractDetailsID = 0,
                                s_ContractFile      = Convert.ToString(Common.iffBlank(files[i], ""))
                            });
                        }
                    }

                    if (ddlAmendments.SelectedItem.Text.ToLower() == "yes")
                    {
                        cd.b_Amendments = Convert.ToInt32(Common.iffBlank(ddlAmendments.SelectedItem.Value, 0)) == 1 ? true : false;

                        cd.dt_NewExpiry_Date         = Convert.ToString(Common.iffBlank(TxtNContractExpiryDate.Text, ""));
                        cd.s_AmendmenstContract_File = Convert.ToString(Common.iffBlank((fldAmendmentFile.HasFile) ? String.Join(",", Common.UpLoadNew(fldAmendmentFile, Common.FolderLocation.ContractMgmtUser).Select(r => r.ToString())) : HdnAmendPath.Value, ""));
                        if (HdnAmendPath.Value.Length > 0)
                        {
                            cd.s_AmendmenstContract_File = (cd.s_AmendmenstContract_File != "") ? cd.s_AmendmenstContract_File : HdnAmendPath.Value;
                        }
                    }
                }

                //--------UID and UName----
                cd.UName = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserName"]), "").ToString();
                cd.UID   = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserID"]), "").ToString();
                //----------- END ------------

                result = cl.Contract_Details_DML(cd, lstSelCollab.ToArray(), lstSelClause.ToArray(), lstmultiple.ToArray(), HdnContractMode.Value);

                //}
                if (result.Split('|')[0].ToLower().Trim() == "success" && result.Split('|')[1].ToLower().CheckInt() == true)
                {
                    switch (HdnContractMode.Value.ToLower())
                    {
                    case "update": this.PopUpMsg("Contract Detail Update  Successfully..!!", "AfterSave();"); break;

                    case "delete": this.PopUpMsg("Contract Detail Delete  Successfully..!!", "AfterSave();"); break;

                    case "insert": this.PopUpMsg("Contract Detail Save  Successfully..!!", "AfterSave();"); break;
                    }
                    btnResets_Click(null, null);
                    btnContractSave.Text = "Save";
                    HdnContractId.Value  = result.Split('|')[1];
                    //ClearContractControlAfterSave();
                    FillControl();
                }
                else
                {
                    this.MsgBox(result.Split('|')[1]);
                    return(false);
                }
            }
            //}

            //}
            catch (Exception ex)
            {
                this.MsgBox(ex.Message);
                return(false);
            }
            return(true);
        }