protected void delete_Click(object sender, EventArgs e)
        {
            string rs = "";

            // TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            try
            {
                Project_Master pm = new Project_Master();
                pm.i_ID = Int32.Parse(HdnId.Value);
                ProjectMasterModel pmm = new ProjectMasterModel()
                {
                    _Project_Master = pm, mode = "Delete"
                };
                using (var client = new System.Net.Http.HttpClient())
                {
                    //client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var         json    = Newtonsoft.Json.JsonConvert.SerializeObject(pmm);
                    HttpContent content = new StringContent(json);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    // var response = client.PostAsJsonAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", pmm).Result;
                    var response = client.PostAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        // by calling .Result you are performing a synchronous call
                        var responseContent = response.Content;

                        // by calling .Result you are synchronously reading the result
                        rs = responseContent.ReadAsStringAsync().Result;
                    }
                }
                if (rs != "")
                {
                    this.MsgBox("Project Details Deleted Successfully..!!");
                    ShowPanel();
                    FillGridMain();
                }
                // rs = cl.GetValidate("Delete_Project", "1", "admin", HdnId.Value, "");
                //if (rs != "")
                //{
                //    this.MsgBox("Project Details Deleted Successfully..!!");
                //    ShowPanel();
                //    FillGridMain();
                //}
            }
            catch (Exception ex)
            {
                this.MsgBox(ex.Message.ToString());
            }
        }
        protected async void FillControl()
        {
            
            Project_Master plist = new Project_Master();
            List<PI_Master> List_DEPT_PI = new List<PI_Master>();
            List<Project_Coordinator_Details> List_Co_Ord = new List<Project_Coordinator_Details>();
            try
            {
                ShowPanel("entry");
                // plist = cl.GetProject_MasterDetailsByID(Convert.ToInt32(Common.iffBlank(HdnId.Value, 0)));
                ProjectMasterModel pmm = new ProjectMasterModel();
                using (var client = new HttpClient())
                {
                   // client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiUrl"].ToString());
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString());
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response =await client.GetAsync(string.Format("api/ProjectMaster/{0}", Convert.ToInt32(Common.iffBlank(HdnId.Value, 0))));
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    pmm = serializer.Deserialize<ProjectMasterModel>(response.Content.ReadAsStringAsync().Result);
                }
               // BindCombo();
                BindCoOrdinator();
                plist = pmm._Project_Master;
                TxtDispProjId.Text = Common.GetReplace(plist.s_Display_Project_ID);
                DispProjectId.InnerText = TxtDispProjId.Text;
                TxtstartDate.Text = plist.Project_StartDate;
                TxtprojTitle.Text = Common.GetReplace(plist.s_Project_Title);
                TxtShortTitle.Text = Common.GetReplace(plist.s_Short_Title);
                TxtProjTitleAlias1.Text = Common.GetReplace(plist.s_Project_Alias1);
                TxtProjTitleAlias2.Text = Common.GetReplace(plist.s_Project_Alias2);
                TxtProjDescription.Text = Common.GetReplace(plist.s_Project_Desc);
                TxtIRBno.Text = Common.GetReplace(plist.s_IRB_No);

                ddlProjCategory.SelectedIndex = ddlProjCategory.Items.IndexOf(ddlProjCategory.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Category_ID, ""))));
                ddlProjType.SelectedIndex = ddlProjType.Items.IndexOf(ddlProjType.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Type_ID, ""))));
                ddlProjType_SelectedIndexChanged(null, null);
                ddlProjSubType.SelectedIndex = ddlProjSubType.Items.IndexOf(ddlProjSubType.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Subtype_ID, ""))));
                ddlProjSubType.Enabled = (ddlProjSubType.SelectedIndex > 0) ? true : false;
                ddlFeasibilityStatus.SelectedIndex = ddlFeasibilityStatus.Items.IndexOf(ddlFeasibilityStatus.Items.FindByValue(Convert.ToString(plist.b_IsFeasible)));
                HdnFeasibilityStatus.Value = Convert.ToString(plist.b_IsFeasible);
                ddlselectedproject.SelectedIndex = ddlselectedproject.Items.IndexOf(ddlselectedproject.Items.FindByValue(Convert.ToString(plist.b_Isselected_project == true ? "1" : "0")));
                ddlCollbrationInv.SelectedIndex = ddlCollbrationInv.Items.IndexOf(ddlCollbrationInv.Items.FindByValue(Convert.ToString(plist.b_Collaboration_Involved == true ? "1" : "0")));
                if (ddlProjCategory.SelectedItem.Text.ToLower() == "pharma")
                {
                    ddlCollbrationInv.Enabled = false;
                }
                ddlstartbyTTSH.SelectedIndex = ddlstartbyTTSH.Items.IndexOf(ddlstartbyTTSH.Items.FindByValue(Convert.ToString(plist.b_StartBy_TTSH == true ? "1" : "0")));
                ddlfundingReq.SelectedIndex = ddlfundingReq.Items.IndexOf(ddlfundingReq.Items.FindByValue(Convert.ToString(plist.b_Funding_req == true ? "1" : "0")));
                ddlChildParent.SelectedIndex = ddlChildParent.Items.IndexOf(ddlChildParent.Items.FindByValue(Convert.ToString(plist.b_Ischild == true ? "0" : "1")));
                if (ddlChildParent.SelectedValue == "0")
                {
                    ddlParentProjName.Enabled = true; txtParentProjId.Enabled = true;
                    ddlParentProjName.SelectedIndex = ddlParentProjName.Items.IndexOf(ddlParentProjName.Items.FindByValue(Convert.ToString(plist.i_Parent_ProjectID)));
                    ddlParentProjName_SelectedIndexChanged(null, null);
                }
                else
                {
                    ddlParentProjName.Enabled = false; txtParentProjId.Enabled = false;
                }

                //-------Newly Added 31-08-2015------------
                ddlProjectStatus.SelectedIndex = ddlProjectStatus.Items.IndexOf(ddlProjectStatus.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_ProjectStatus, ""))));
                TxtProjectEndDate.Text = Convert.ToString(plist.Dt_ProjectEndDate);
                ddlEthicsNeeded.SelectedValue = (plist.b_EthicsNeeded == true) ? "1" : "0";
                //---- END---------------------------------


                ScriptManager.RegisterStartupScript(Page, typeof(Page), "Enable", "BindDoObjects();", true);
                /*dataowner fill*/
                ddlDO_Ethics.SelectedIndex = ddlDO_Ethics.Items.IndexOf(ddlDO_Ethics.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Ethics_DataOwner, ""))));
                ddlDO_Feasibility.SelectedIndex = ddlDO_Feasibility.Items.IndexOf(ddlDO_Feasibility.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Feasibility_DataOwner, ""))));
                ddlDO_Contract.SelectedIndex = ddlDO_Contract.Items.IndexOf(ddlDO_Contract.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Contract_DataOwner, ""))));
                ddlDO_Selected.SelectedIndex = ddlDO_Selected.Items.IndexOf(ddlDO_Ethics.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Selected_DataOwner, ""))));
                ddlDO_Regulatory.SelectedIndex = ddlDO_Regulatory.Items.IndexOf(ddlDO_Regulatory.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Regulatory_DataOwner, ""))));
                ddlDO_Grant.SelectedIndex = ddlDO_Grant.Items.IndexOf(ddlDO_Grant.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Grant_DataOwner, ""))));

                //Page.ClientScript.RegisterStartupScript(this.GetType(), "enable", "alert('Hello!')", true);

                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "enable", "BindDoObjects();", true);
                /**/

                List_DEPT_PI = pmm.DEPT_PI.ToList(); //plist.DEPT_PI.ToList();
                var q = (from i in List_DEPT_PI select new { i.i_Dept_ID, i.i_ID }).ToList().ListToDatatable();
                rptrPIDetails.DataSource = List_DEPT_PI;
                rptrPIDetails.DataBind();

                txtResearchOrder.Text = Common.GetReplace(plist.s_Research_IO);
                txtReserchInsurance.Text = Common.GetReplace(plist.s_Research_IP);
                List_Co_Ord = pmm.pcd.ToList(); //plist.COORDINATOR.ToList();
                for (int j = 0; j < chkboxlist.Items.Count; j++)
                {
                    for (int i = 0; i < List_Co_Ord.Count; i++)
                    {
                        if (chkboxlist.Items[j].Value == Convert.ToString(List_Co_Ord[i].i_Coordinator_ID))
                        {
                            chkboxlist.Items[j].Selected = true;
                            TextSearch.Text += chkboxlist.Items[j].Text + ",";
                        }
                    }
                }
                if (TextSearch.Text != "")
                {
                    TextSearch.Text = TextSearch.Text.TrimEnd(',');

                }

                //	TxtDispProjId.Attributes.Add("onblur", "javascript:return GetValidatefrmDB('" + HdnError.ClientID + "','ValidateDispID' ,'" + TxtDispProjId.ClientID + "','" + HdnId.Value + "');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", "ClearAll('" + HdnMode.Value + "');", true);

                if (HdnMode.Value.ToLower() == "update")
                {

                   // String s = cl.GetValidate("RestrictChild", HdnId.Value, "", "", "");
                    //if (s != "")
                    //{
                    //    ddlChildParent.Enabled = false;
                    //    ddlChildParent.Attributes.Add("title", "Child Project is Created for this Project..!!");
                    //}
                }
                ChangeButtonText();

                MakeControlValidate();
               
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public bool Save()
        {
            string result = string.Empty;
            Project_Master pm = new Project_Master();
            Project_Dept_PI pdi = new Project_Dept_PI();
            List<Project_Dept_PI> pdlist = new List<Project_Dept_PI>();
            Project_Coordinator_Details pcd = new Project_Coordinator_Details();
            List<Project_Coordinator_Details> pcdList = new List<Project_Coordinator_Details>();
            try
            {

                pm.i_ID = Convert.ToInt32(Common.iffBlank(HdnId.Value, 0));
                TxtstartDate.Enabled = true;
                TxtDispProjId.Enabled = true;
                pm.Project_StartDate = TxtstartDate.Text;
                pm.s_Display_Project_ID = TxtDispProjId.Text;
                pm.s_Project_Title = Common.SetReplace(TxtprojTitle.Text);
                pm.s_Short_Title = Common.SetReplace(TxtShortTitle.Text);
                pm.s_Project_Alias1 = Common.SetReplace(TxtProjTitleAlias1.Text);
                pm.s_Project_Alias2 = Common.SetReplace(TxtProjTitleAlias2.Text);
                pm.s_Project_Desc = Common.SetReplace(TxtProjDescription.Text);
                pm.s_IRB_No = Common.SetReplace(TxtIRBno.Text);
                pm.i_Project_Category_ID = Convert.ToInt32(Common.iffBlank(ddlProjCategory.SelectedValue, 0));
                pm.i_Project_Type_ID = Convert.ToInt32(Common.iffBlank(ddlProjType.SelectedValue, 0));
                pm.i_Project_Subtype_ID = Convert.ToInt32(Common.iffBlank(ddlProjSubType.SelectedValue, 0));
                pm.i_Parent_ProjectID = Convert.ToInt32(ddlParentProjName.SelectedValue);
                pm.b_IsFeasible = Convert.ToInt32(ddlFeasibilityStatus.SelectedValue);
                pm.b_Isselected_project = ddlselectedproject.SelectedValue == "0" ? false : true;
                pm.b_Collaboration_Involved = ddlCollbrationInv.SelectedValue == "0" ? false : true;
                pm.b_StartBy_TTSH = ddlstartbyTTSH.SelectedValue == "0" ? false : true;
                pm.b_Funding_req = ddlfundingReq.SelectedValue == "0" ? false : true;
                pm.b_Ischild = ddlChildParent.SelectedValue == "1" ? false : true;
                pm.s_Research_IO = txtResearchOrder.Text;
                pm.s_Research_IP = txtReserchInsurance.Text;
                //-------------pass tables to Sp-------------------------
                string[] PiIds = HdnPi_ID.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int i = 0; i < PiIds.Length; i++)
                {
                    pdlist.Add(new Project_Dept_PI { i_PI_ID = Convert.ToInt32(PiIds[i]) });
                }

                string[] coOrIds = HdnCoordinatorId.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                string[] CoText = HdnCoordinatorText.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int i = 0; i < coOrIds.Length; i++)
                {
                    pcdList.Add(new Project_Coordinator_Details { i_Coordinator_ID = Convert.ToString(coOrIds[i]), s_Coordinator_name = CoText[i] });
                }

                //--------UID and UName----
                pm.UName = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserName"]), "").ToString();
                pm.UID = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserID"]), "").ToString();
                pm.i_ProjectStatus = Convert.ToInt32(ddlProjectStatus.SelectedValue);
                pm.Dt_ProjectEndDate = Convert.ToString(TxtProjectEndDate.Text);
                pm.b_EthicsNeeded = (ddlEthicsNeeded.SelectedItem.Text.ToLower() == "yes") ? true : false;

                //----------- END ------------

                /*data owner*/
                //pm.s_Ethics_DataOwner = (ddlDO_Ethics.SelectedValue != "0") ? ddlDO_Ethics.SelectedValue : null;
                //pm.s_Selected_DataOwner = (ddlDO_Selected.SelectedValue != "0") ? ddlDO_Selected.SelectedValue : null;
                //pm.s_Regulatory_DataOwner = (ddlDO_Regulatory.SelectedValue != "0") ? ddlDO_Regulatory.SelectedValue : null;
                //pm.s_Feasibility_DataOwner = (ddlDO_Feasibility.SelectedValue != "0") ? ddlDO_Feasibility.SelectedValue : null;
                //pm.s_Contract_DataOwner = (ddlDO_Contract.SelectedValue != "0") ? ddlDO_Contract.SelectedValue : null;
                //pm.s_Grant_DataOwner = (ddlDO_Grant.SelectedValue != "0") ? ddlDO_Grant.SelectedValue : null;
                /*data owner*/

                //---------------------------------------------------------
                //result = cl.Project_Master(pm, pdlist.ToArray(), pcdList.ToArray(), HdnMode.Value);

                //const string url = "http://localhost/ConsumingAPI/api/Products";

                System.Collections.ArrayList paraMeters = new System.Collections.ArrayList();
                paraMeters.Add(pm);
                paraMeters.Add(pdlist.ToArray());
                paraMeters.Add(pcdList.ToArray());
                paraMeters.Add(HdnMode.Value.ToString());
                ProjectMasterModel pmm = new ProjectMasterModel() { _Project_Master = pm, pdi = pdlist, pcd = pcdList, mode = HdnMode.Value };
                using (var client = new System.Net.Http.HttpClient())
                {
                    // client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(pmm);
                    HttpContent content = new StringContent(json);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                   // var response = client.PostAsJsonAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", pmm).Result;
                    var response = client.PostAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        // by calling .Result you are performing a synchronous call
                        var responseContent = response.Content;

                        // by calling .Result you are synchronously reading the result
                         result = responseContent.ReadAsStringAsync().Result;

                    }
                }
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Add", string.Format("javascript:AddProjectMaster({0},{1})",pmm, System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/"), true);
                if (result.Split('|')[0].ToLower().Trim() == "success" && result.Split('|')[1].ToLower().Trim().CheckInt() == true)
                {
                    switch (HdnMode.Value.ToLower())
                    {
                        case "update": this.MsgBox("Project Details Updated Successfully"); break;
                        case "delete": this.MsgBox("Project Details Deleted Successfully"); break;
                        case "insert": this.MsgBox(" Project Details Saved Successfully"); break;
                    }
                    ShowPanel();
                    FillGridMain();
                }
                else
                {
                    this.MsgBox(result.Split('|')[1]);
                    return false;
                }
            }
            catch (Exception ex)
            {
                this.MsgBox(ex.ToString());
                return false;
            }

            return true;
        }
        protected void delete_Click(object sender, EventArgs e)
        {
            string rs = "";
           // TTSHWCFServiceClient cl = new TTSHWCFServiceClient();
            try
            {
                Project_Master pm = new Project_Master();
                pm.i_ID =Int32.Parse(HdnId.Value);
                ProjectMasterModel pmm = new ProjectMasterModel() { _Project_Master = pm,  mode = "Delete" };
                using (var client = new System.Net.Http.HttpClient())
                {
                    //client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString()+ "api/ProjectMaster/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(pmm);
                    HttpContent content = new StringContent(json);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    // var response = client.PostAsJsonAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", pmm).Result;
                    var response = client.PostAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        // by calling .Result you are performing a synchronous call
                        var responseContent = response.Content;

                        // by calling .Result you are synchronously reading the result
                        rs = responseContent.ReadAsStringAsync().Result;

                    }
                }
                if (rs != "")
                {
                    this.MsgBox("Project Details Deleted Successfully..!!");
                    ShowPanel();
                    FillGridMain();
                }
                // rs = cl.GetValidate("Delete_Project", "1", "admin", HdnId.Value, "");
                //if (rs != "")
                //{
                //    this.MsgBox("Project Details Deleted Successfully..!!");
                //    ShowPanel();
                //    FillGridMain();
                //}
            }
            catch (Exception ex)
            {
                this.MsgBox(ex.Message.ToString());
            }
        }
        protected async void FillControl()
        {
            Project_Master   plist        = new Project_Master();
            List <PI_Master> List_DEPT_PI = new List <PI_Master>();
            List <Project_Coordinator_Details> List_Co_Ord = new List <Project_Coordinator_Details>();

            try
            {
                ShowPanel("entry");
                // plist = cl.GetProject_MasterDetailsByID(Convert.ToInt32(Common.iffBlank(HdnId.Value, 0)));
                ProjectMasterModel pmm = new ProjectMasterModel();
                using (var client = new HttpClient())
                {
                    // client.BaseAddress = new Uri(ConfigurationManager.AppSettings["WebApiUrl"].ToString());
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString());
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    HttpResponseMessage response = await client.GetAsync(string.Format("api/ProjectMaster/{0}", Convert.ToInt32(Common.iffBlank(HdnId.Value, 0))));

                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    pmm = serializer.Deserialize <ProjectMasterModel>(response.Content.ReadAsStringAsync().Result);
                }
                // BindCombo();
                BindCoOrdinator();
                plist = pmm._Project_Master;
                TxtDispProjId.Text      = Common.GetReplace(plist.s_Display_Project_ID);
                DispProjectId.InnerText = TxtDispProjId.Text;
                TxtstartDate.Text       = plist.Project_StartDate;
                TxtprojTitle.Text       = Common.GetReplace(plist.s_Project_Title);
                TxtShortTitle.Text      = Common.GetReplace(plist.s_Short_Title);
                TxtProjTitleAlias1.Text = Common.GetReplace(plist.s_Project_Alias1);
                TxtProjTitleAlias2.Text = Common.GetReplace(plist.s_Project_Alias2);
                TxtProjDescription.Text = Common.GetReplace(plist.s_Project_Desc);
                TxtIRBno.Text           = Common.GetReplace(plist.s_IRB_No);

                ddlProjCategory.SelectedIndex = ddlProjCategory.Items.IndexOf(ddlProjCategory.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Category_ID, ""))));
                ddlProjType.SelectedIndex     = ddlProjType.Items.IndexOf(ddlProjType.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Type_ID, ""))));
                ddlProjType_SelectedIndexChanged(null, null);
                ddlProjSubType.SelectedIndex       = ddlProjSubType.Items.IndexOf(ddlProjSubType.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_Project_Subtype_ID, ""))));
                ddlProjSubType.Enabled             = (ddlProjSubType.SelectedIndex > 0) ? true : false;
                ddlFeasibilityStatus.SelectedIndex = ddlFeasibilityStatus.Items.IndexOf(ddlFeasibilityStatus.Items.FindByValue(Convert.ToString(plist.b_IsFeasible)));
                HdnFeasibilityStatus.Value         = Convert.ToString(plist.b_IsFeasible);
                ddlselectedproject.SelectedIndex   = ddlselectedproject.Items.IndexOf(ddlselectedproject.Items.FindByValue(Convert.ToString(plist.b_Isselected_project == true ? "1" : "0")));
                ddlCollbrationInv.SelectedIndex    = ddlCollbrationInv.Items.IndexOf(ddlCollbrationInv.Items.FindByValue(Convert.ToString(plist.b_Collaboration_Involved == true ? "1" : "0")));
                if (ddlProjCategory.SelectedItem.Text.ToLower() == "pharma")
                {
                    ddlCollbrationInv.Enabled = false;
                }
                ddlstartbyTTSH.SelectedIndex = ddlstartbyTTSH.Items.IndexOf(ddlstartbyTTSH.Items.FindByValue(Convert.ToString(plist.b_StartBy_TTSH == true ? "1" : "0")));
                ddlfundingReq.SelectedIndex  = ddlfundingReq.Items.IndexOf(ddlfundingReq.Items.FindByValue(Convert.ToString(plist.b_Funding_req == true ? "1" : "0")));
                ddlChildParent.SelectedIndex = ddlChildParent.Items.IndexOf(ddlChildParent.Items.FindByValue(Convert.ToString(plist.b_Ischild == true ? "0" : "1")));
                if (ddlChildParent.SelectedValue == "0")
                {
                    ddlParentProjName.Enabled       = true; txtParentProjId.Enabled = true;
                    ddlParentProjName.SelectedIndex = ddlParentProjName.Items.IndexOf(ddlParentProjName.Items.FindByValue(Convert.ToString(plist.i_Parent_ProjectID)));
                    ddlParentProjName_SelectedIndexChanged(null, null);
                }
                else
                {
                    ddlParentProjName.Enabled = false; txtParentProjId.Enabled = false;
                }

                //-------Newly Added 31-08-2015------------
                ddlProjectStatus.SelectedIndex = ddlProjectStatus.Items.IndexOf(ddlProjectStatus.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.i_ProjectStatus, ""))));
                TxtProjectEndDate.Text         = Convert.ToString(plist.Dt_ProjectEndDate);
                ddlEthicsNeeded.SelectedValue  = (plist.b_EthicsNeeded == true) ? "1" : "0";
                //---- END---------------------------------


                ScriptManager.RegisterStartupScript(Page, typeof(Page), "Enable", "BindDoObjects();", true);
                /*dataowner fill*/
                ddlDO_Ethics.SelectedIndex      = ddlDO_Ethics.Items.IndexOf(ddlDO_Ethics.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Ethics_DataOwner, ""))));
                ddlDO_Feasibility.SelectedIndex = ddlDO_Feasibility.Items.IndexOf(ddlDO_Feasibility.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Feasibility_DataOwner, ""))));
                ddlDO_Contract.SelectedIndex    = ddlDO_Contract.Items.IndexOf(ddlDO_Contract.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Contract_DataOwner, ""))));
                ddlDO_Selected.SelectedIndex    = ddlDO_Selected.Items.IndexOf(ddlDO_Ethics.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Selected_DataOwner, ""))));
                ddlDO_Regulatory.SelectedIndex  = ddlDO_Regulatory.Items.IndexOf(ddlDO_Regulatory.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Regulatory_DataOwner, ""))));
                ddlDO_Grant.SelectedIndex       = ddlDO_Grant.Items.IndexOf(ddlDO_Grant.Items.FindByValue(Convert.ToString(Common.iffBlank(plist.s_Grant_DataOwner, ""))));

                //Page.ClientScript.RegisterStartupScript(this.GetType(), "enable", "alert('Hello!')", true);

                //ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "enable", "BindDoObjects();", true);
                /**/

                List_DEPT_PI = pmm.DEPT_PI.ToList(); //plist.DEPT_PI.ToList();
                var q = (from i in List_DEPT_PI select new { i.i_Dept_ID, i.i_ID }).ToList().ListToDatatable();
                rptrPIDetails.DataSource = List_DEPT_PI;
                rptrPIDetails.DataBind();

                txtResearchOrder.Text    = Common.GetReplace(plist.s_Research_IO);
                txtReserchInsurance.Text = Common.GetReplace(plist.s_Research_IP);
                List_Co_Ord = pmm.pcd.ToList(); //plist.COORDINATOR.ToList();
                for (int j = 0; j < chkboxlist.Items.Count; j++)
                {
                    for (int i = 0; i < List_Co_Ord.Count; i++)
                    {
                        if (chkboxlist.Items[j].Value == Convert.ToString(List_Co_Ord[i].i_Coordinator_ID))
                        {
                            chkboxlist.Items[j].Selected = true;
                            TextSearch.Text += chkboxlist.Items[j].Text + ",";
                        }
                    }
                }
                if (TextSearch.Text != "")
                {
                    TextSearch.Text = TextSearch.Text.TrimEnd(',');
                }

                //	TxtDispProjId.Attributes.Add("onblur", "javascript:return GetValidatefrmDB('" + HdnError.ClientID + "','ValidateDispID' ,'" + TxtDispProjId.ClientID + "','" + HdnId.Value + "');");
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", "ClearAll('" + HdnMode.Value + "');", true);

                if (HdnMode.Value.ToLower() == "update")
                {
                    // String s = cl.GetValidate("RestrictChild", HdnId.Value, "", "", "");
                    //if (s != "")
                    //{
                    //    ddlChildParent.Enabled = false;
                    //    ddlChildParent.Attributes.Add("title", "Child Project is Created for this Project..!!");
                    //}
                }
                ChangeButtonText();

                MakeControlValidate();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool Save()
        {
            string                             result  = string.Empty;
            Project_Master                     pm      = new Project_Master();
            Project_Dept_PI                    pdi     = new Project_Dept_PI();
            List <Project_Dept_PI>             pdlist  = new List <Project_Dept_PI>();
            Project_Coordinator_Details        pcd     = new Project_Coordinator_Details();
            List <Project_Coordinator_Details> pcdList = new List <Project_Coordinator_Details>();

            try
            {
                pm.i_ID = Convert.ToInt32(Common.iffBlank(HdnId.Value, 0));
                TxtstartDate.Enabled        = true;
                TxtDispProjId.Enabled       = true;
                pm.Project_StartDate        = TxtstartDate.Text;
                pm.s_Display_Project_ID     = TxtDispProjId.Text;
                pm.s_Project_Title          = Common.SetReplace(TxtprojTitle.Text);
                pm.s_Short_Title            = Common.SetReplace(TxtShortTitle.Text);
                pm.s_Project_Alias1         = Common.SetReplace(TxtProjTitleAlias1.Text);
                pm.s_Project_Alias2         = Common.SetReplace(TxtProjTitleAlias2.Text);
                pm.s_Project_Desc           = Common.SetReplace(TxtProjDescription.Text);
                pm.s_IRB_No                 = Common.SetReplace(TxtIRBno.Text);
                pm.i_Project_Category_ID    = Convert.ToInt32(Common.iffBlank(ddlProjCategory.SelectedValue, 0));
                pm.i_Project_Type_ID        = Convert.ToInt32(Common.iffBlank(ddlProjType.SelectedValue, 0));
                pm.i_Project_Subtype_ID     = Convert.ToInt32(Common.iffBlank(ddlProjSubType.SelectedValue, 0));
                pm.i_Parent_ProjectID       = Convert.ToInt32(ddlParentProjName.SelectedValue);
                pm.b_IsFeasible             = Convert.ToInt32(ddlFeasibilityStatus.SelectedValue);
                pm.b_Isselected_project     = ddlselectedproject.SelectedValue == "0" ? false : true;
                pm.b_Collaboration_Involved = ddlCollbrationInv.SelectedValue == "0" ? false : true;
                pm.b_StartBy_TTSH           = ddlstartbyTTSH.SelectedValue == "0" ? false : true;
                pm.b_Funding_req            = ddlfundingReq.SelectedValue == "0" ? false : true;
                pm.b_Ischild                = ddlChildParent.SelectedValue == "1" ? false : true;
                pm.s_Research_IO            = txtResearchOrder.Text;
                pm.s_Research_IP            = txtReserchInsurance.Text;
                //-------------pass tables to Sp-------------------------
                string[] PiIds = HdnPi_ID.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int i = 0; i < PiIds.Length; i++)
                {
                    pdlist.Add(new Project_Dept_PI {
                        i_PI_ID = Convert.ToInt32(PiIds[i])
                    });
                }

                string[] coOrIds = HdnCoordinatorId.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                string[] CoText  = HdnCoordinatorText.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.ToString()).ToArray();
                for (int i = 0; i < coOrIds.Length; i++)
                {
                    pcdList.Add(new Project_Coordinator_Details {
                        i_Coordinator_ID = Convert.ToString(coOrIds[i]), s_Coordinator_name = CoText[i]
                    });
                }

                //--------UID and UName----
                pm.UName             = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserName"]), "").ToString();
                pm.UID               = Common.iffBlank(Convert.ToString(HttpContext.Current.Session["UserID"]), "").ToString();
                pm.i_ProjectStatus   = Convert.ToInt32(ddlProjectStatus.SelectedValue);
                pm.Dt_ProjectEndDate = Convert.ToString(TxtProjectEndDate.Text);
                pm.b_EthicsNeeded    = (ddlEthicsNeeded.SelectedItem.Text.ToLower() == "yes") ? true : false;

                //----------- END ------------

                /*data owner*/
                //pm.s_Ethics_DataOwner = (ddlDO_Ethics.SelectedValue != "0") ? ddlDO_Ethics.SelectedValue : null;
                //pm.s_Selected_DataOwner = (ddlDO_Selected.SelectedValue != "0") ? ddlDO_Selected.SelectedValue : null;
                //pm.s_Regulatory_DataOwner = (ddlDO_Regulatory.SelectedValue != "0") ? ddlDO_Regulatory.SelectedValue : null;
                //pm.s_Feasibility_DataOwner = (ddlDO_Feasibility.SelectedValue != "0") ? ddlDO_Feasibility.SelectedValue : null;
                //pm.s_Contract_DataOwner = (ddlDO_Contract.SelectedValue != "0") ? ddlDO_Contract.SelectedValue : null;
                //pm.s_Grant_DataOwner = (ddlDO_Grant.SelectedValue != "0") ? ddlDO_Grant.SelectedValue : null;
                /*data owner*/

                //---------------------------------------------------------
                //result = cl.Project_Master(pm, pdlist.ToArray(), pcdList.ToArray(), HdnMode.Value);

                //const string url = "http://localhost/ConsumingAPI/api/Products";

                System.Collections.ArrayList paraMeters = new System.Collections.ArrayList();
                paraMeters.Add(pm);
                paraMeters.Add(pdlist.ToArray());
                paraMeters.Add(pcdList.ToArray());
                paraMeters.Add(HdnMode.Value.ToString());
                ProjectMasterModel pmm = new ProjectMasterModel()
                {
                    _Project_Master = pm, pdi = pdlist, pcd = pcdList, mode = HdnMode.Value
                };
                using (var client = new System.Net.Http.HttpClient())
                {
                    // client.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.BaseAddress = new Uri(Session["WebApiUrl"].ToString() + "api/ProjectMaster/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    var         json    = Newtonsoft.Json.JsonConvert.SerializeObject(pmm);
                    HttpContent content = new StringContent(json);
                    content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    // var response = client.PostAsJsonAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", pmm).Result;
                    var response = client.PostAsync(System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/", content).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        // by calling .Result you are performing a synchronous call
                        var responseContent = response.Content;

                        // by calling .Result you are synchronously reading the result
                        result = responseContent.ReadAsStringAsync().Result;
                    }
                }
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Add", string.Format("javascript:AddProjectMaster({0},{1})",pmm, System.Configuration.ConfigurationManager.AppSettings["WebApiUrl"].ToString() + "api/ProjectMaster/"), true);
                if (result.Split('|')[0].ToLower().Trim() == "success" && result.Split('|')[1].ToLower().Trim().CheckInt() == true)
                {
                    switch (HdnMode.Value.ToLower())
                    {
                    case "update": this.MsgBox("Project Details Updated Successfully"); break;

                    case "delete": this.MsgBox("Project Details Deleted Successfully"); break;

                    case "insert": this.MsgBox(" Project Details Saved Successfully"); break;
                    }
                    ShowPanel();
                    FillGridMain();
                }
                else
                {
                    this.MsgBox(result.Split('|')[1]);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                this.MsgBox(ex.ToString());
                return(false);
            }

            return(true);
        }