public ActionResult DgvClickGetPatientWiseResultForPatientSearch(int LabNo)
      {
          BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
          DataSet ds = new DataSet();
          List <Patient_Wise_Result_Entry> searclist = new List <Models.Laboratory.Patient_Wise_Result_Entry>();

          ds = BL_obj.GetPatientWiseResultForPatientSearch(LabNo);

          // test.Models.Master.MasterLaboratory.Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();

          // searclist.Add(obj);

          foreach (DataRow dr in ds.Tables[1].Rows)
          {
              Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
              obj.LabNo       = ds.Tables[0].Rows[0]["LabNo"].ToString();
              obj.RegNo       = ds.Tables[0].Rows[0]["PatientRegNo"].ToString();
              obj.Patientname = ds.Tables[0].Rows[0]["PatientName"].ToString();
              obj.ConsDr      = ds.Tables[0].Rows[0]["DoctorPrintName"].ToString();


              obj.TestID   = dr["TestID"].ToString();
              obj.Testname = dr["TestName"].ToString();

              searclist.Add(obj);
          }
          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }
      public ActionResult IUPatientLabAuthorization(string AuthorzerID, string AuthorzeName, string stauts, string Remark, string LabNo, string TestID, string TestName, string Mode)
      {
          Patient_Wise_Result_Entry        obj     = new Patient_Wise_Result_Entry();
          List <Patient_Wise_Result_Entry> listAdd = new List <Patient_Wise_Result_Entry>();

          BL_Patient_Wise_Result_Entry OBJ_bl = new BL_Patient_Wise_Result_Entry();

          if (Mode == "Save")
          {
              Mode = "Add";
          }
          else
          {
              Mode = "Edit";
          }
          bool chk = OBJ_bl.IUPatientLabAuthorization(AuthorzerID, AuthorzeName, stauts, Remark, LabNo, TestID, TestName, Mode);

          if (chk)
          {
              obj.Message = "You are  Save Authoriser .";
          }
          else
          {
              obj.Message = "You are not Save Authoriser .";
          }
          listAdd.Add(obj);
          return(Json(listAdd, JsonRequestBehavior.AllowGet));
      }
      //public ActionResult GetParamater(string footer)
      // {

      //     return Json(searclist, JsonRequestBehavior.AllowGet);
      // }
      public ActionResult GetParamaterHelpValue(string ParameterID)
      {
          BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
          DataSet ds = new DataSet();
          List <Patient_Wise_Result_Entry> searclist = new List <Models.Laboratory.Patient_Wise_Result_Entry>();

          DataSet dsDetail = new DataSet();

          dsDetail = BL_obj.GetParamaterHelpValue(Convert.ToInt32(ParameterID));
          foreach (DataRow dr in dsDetail.Tables[0].Rows)
          {
              Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
              //  dr["Formula"] = "5";
              obj.ParamiterID = dr["ParameterID1"].ToString();
              obj.HelpValueID = dr["HelpValueID"].ToString();
              obj.HelpValue   = dr["HelpValue"].ToString();



              searclist.Add(obj);
          }



          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }
      public ActionResult RechkCompletebtn(int LabNo, string ParamiterID, string TestID2, string Formula, string newValue, string NLH1, string col)
      {
          Connect();
          string Message = "";

          if (newValue.ToString().Trim().Length > 0)
          {
              string[] NLH = NLH1.Split(',');

              BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
              Patient_Wise_Result_Entry    obj    = new Patient_Wise_Result_Entry();
              Calculation(LabNo, ParamiterID, TestID2, Formula, newValue, NLH1);
              if (TestID2 == "")
              {
                  TestID2 = "0";
              }
              dsCompare = BL_obj.GetPatientWiseResultforParameterValue(Convert.ToInt32(LabNo), Convert.ToInt32(dsPatientEntry.Tables[0].Rows[0]["TestID"]));

              if (dsPatientEntry.Tables.Count > 0)
              {
                  int i = 0;
                  foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
                  {
                      if (dsCompare.Tables[0].Rows[i]["ResultValue"].ToString().Trim() != dr["ResultValue"].ToString().Trim())
                      {
                          dr["CreationID"] = CreationID;
                      }
                      else
                      {
                          dr["CreationID"] = dsCompare.Tables[0].Rows[i]["CreationID"].ToString().Trim();
                      }

                      if (NLH[i] == "Blank")
                      {
                          dr["NLH"] = "";
                      }
                      else
                      {
                          dr["NLH"] = NLH[i];
                      }
                      dr["CompleteBy"] = CreationID;
                      dr["Mode"]       = "Edit";
                      i++;
                  }
                  if (BL_obj.SaveRechk(dsPatientEntry, col))
                  {
                      Message = "Record Saved successfully";
                      //PatientWiseResultEntry();
                  }
              }
          }
          return(Json(Message, JsonRequestBehavior.AllowGet));
      }
      // Aurthorise

      public ActionResult ValidateUser(string users, string password, string LabNo, string TestID)
      {
          Patient_Wise_Result_Entry        obj     = new Patient_Wise_Result_Entry();
          List <Patient_Wise_Result_Entry> listAdd = new List <Patient_Wise_Result_Entry>();
          int AuthorzerID = 0;
          BL_Patient_Wise_Result_Entry OBJ_bl = new BL_Patient_Wise_Result_Entry();
          DataSet dsUser = OBJ_bl.ValidateUser(users, password);

          if (dsUser.Tables[0].Rows[0]["UserValid"].ToString() == "3")
          {
              obj.Message = "Invalid Username. Please try again";
          }
          else if (dsUser.Tables[0].Rows[0]["UserValid"].ToString() == "0")
          {
              obj.Message = "Invalid Password. Please try again";
          }
          else
          {
              obj.AuthorzerID = dsUser.Tables[0].Rows[0]["UserID"].ToString();
              DataSet dsAuthorzer = OBJ_bl.GetPatientLabForAuthorizer(Convert.ToInt32(obj.AuthorzerID), Convert.ToInt32(LabNo), Convert.ToInt32(TestID));
              if (dsAuthorzer.Tables[0].Rows.Count > 0)
              {
                  obj.AuthorzeName = dsAuthorzer.Tables[0].Rows[0]["AuthoriserName"].ToString();
                  if (dsAuthorzer.Tables[1].Rows.Count > 0)
                  {
                      obj.cmbStatus   = dsAuthorzer.Tables[1].Rows[0]["Status"].ToString();
                      obj.txtRemark   = dsAuthorzer.Tables[1].Rows[0]["Remark"].ToString();
                      obj.btnsaveEdit = "Edit";
                  }
                  else
                  {
                      obj.btnsaveEdit = "Save";
                  }
              }
              else
              {
                  obj.Message = "You are not Authoriser.";
              }
          }
          listAdd.Add(obj);
          return(Json(listAdd, JsonRequestBehavior.AllowGet));
      }
      public ActionResult PatientBind(DateTime FromDate, DateTime Todate)
      {
          BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
          DataSet ds = new DataSet();
          List <Patient_Wise_Result_Entry> searclist = new List <Models.Laboratory.Patient_Wise_Result_Entry>();

          ds = BL_obj.SearchPatientLabResultEntryByNameID("%", FromDate, Todate);


          foreach (DataRow dr in ds.Tables[0].Rows)
          {
              Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();

              obj.Patientname = dr["PatientName"].ToString();
              obj.PatientType = dr["PatientType"].ToString();
              obj.LabNo       = dr["LabNo"].ToString();
              obj.LabDate     = dr["LAB DATE"].ToString();

              searclist.Add(obj);
          }
          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }
      public ActionResult GetPatientLabWithParameterRecheck(int LabNo, int TestID)
      {
          List <Patient_Wise_Result_Entry> searclist = new List <Models.Laboratory.Patient_Wise_Result_Entry>();

          if (TestID > 0)
          {
              BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
              DataSet ds             = new DataSet();
              DataSet dsPatientEntry = new DataSet();
              DataSet dsCompare      = new DataSet();
              dsPatientEntry = BL_obj.GetPatientLabWithParameterRecheck(LabNo, TestID);
              dsCompare      = BL_obj.GetPatientWiseResultforParameterValue(Convert.ToInt32(LabNo), Convert.ToInt32(TestID));

              foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
              {
                  Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                  //  dr["Formula"] = "5";
                  //obj.Formula = dr["Formula"].ToString();
                  obj.LabNo = dr["LabNo"].ToString();
                  // obj.FullName = dr["FullName"].ToString();
                  obj.NLH = dr["NLH"].ToString();
                  // obj.ParamiterName = dr["ParameterName"].ToString();
                  obj.Low         = dr["ConvLow"].ToString();
                  obj.Hiegh       = dr["ConvHigh"].ToString();
                  obj.ParamiterID = dr["ParameterID"].ToString();
                  obj.status      = dr["Status"].ToString();
                  obj.TestID      = dr["TestID"].ToString();
                  obj.ResultValue = dr["ResultValue"].ToString();
                  obj.Value1      = dr["Value1"].ToString();
                  obj.Value2      = dr["Value2"].ToString();
                  obj.Value3      = dr["Value3"].ToString();
                  searclist.Add(obj);
              }
          }
          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }
      public ActionResult Calculation(int LabNo, string ParamiterID, string TestID2, string Formula, string newValue, string NLH1)
      {
          MathParser();
          string FullFormula;

          try
          {
              BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();

              string[] ParamiteID1 = ParamiterID.Split(',');
              string[] TestID1     = TestID2.Split(',');
              string[] Formula1    = Formula.Split(',');
              string[] newValue1   = newValue.Split(',');
              //    string[] footersplit = Footer.Split(',');
              // string[] NLH = NLH1.Split(',');
              dsPatientEntry = BL_obj.GetPatientWiseResultforParameterValue(LabNo, Convert.ToInt32(TestID1[0]));

              var a   = dsPatientEntry.Tables[0].Rows.Count;
              int row = 0;
              foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
              {
                  if (ParamiteID1[row] != "")
                  {
                      dr["ParameterID"] = ParamiteID1[row];
                      dr["TestID"]      = TestID1[0];
                      if (Formula1[row].ToString() == "Blank")
                      {
                          dr["Formula"] = "";
                      }
                      else
                      {
                          dr["Formula"] = Formula1[row];
                      }

                      if (newValue1[row] == "Blank")
                      {
                          dr["ResultValue"] = "";
                      }
                      else
                      {
                          dr["ResultValue"] = newValue1[row];
                      }

                      //if (footersplit[row] == "Blank")
                      //{
                      //    dr["Footer"] = "";
                      //}
                      //else
                      //{
                      //    dr["Footer"] = footersplit[row];
                      //}

                      row++;
                  }
              }

              foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
              {
                  FullFormula = dr["Formula"].ToString().Trim();
                  int ParameterID = Convert.ToInt32(dr["ParameterID"].ToString().Trim());
                  int TestID      = Convert.ToInt32(dr["TestID"].ToString().Trim());
                  if (FullFormula.Trim().Length > 0)
                  {
                      // dr["ResultValue"] = Math.Round(Convert.ToDecimal(Calculate(FormulaFullName(ParameterID, FullFormula, TestID)).ToString()), 2);
                      dr["ResultValue"] = Math.Round(Convert.ToDecimal(Calculate(FormulaFullName(ParameterID, FullFormula, TestID).ToString())), 2);
                      //  dr["ResultValue"] = Math.Round(Convert.ToDecimal(Evaluate(FormulaFullName(ParameterID, FullFormula, TestID)).ToString()), 2);
                  }
              }
          }


          catch (Exception ex)
          {
              //ExceptionManager.Publish(ex);
              // ShowMessage(ex.Message, MessageTypes.ErrorMessage);
          }
          foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
          {
              Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
              //  dr["Formula"] = "5";
              obj.Formula       = dr["Formula"].ToString();
              obj.LabNo         = dr["LabNo"].ToString();
              obj.FullName      = dr["FullName"].ToString();
              obj.NLH           = dr["NLH"].ToString();
              obj.ParamiterName = dr["ParameterName"].ToString();
              obj.Low           = dr["ConvLow"].ToString();
              obj.Hiegh         = dr["ConvHigh"].ToString();
              obj.ParamiterID   = dr["ParameterID"].ToString();
              obj.status        = dr["Status"].ToString();
              obj.TestID        = dr["TestID"].ToString();
              obj.ResultValue   = dr["ResultValue"].ToString();
              searclist.Add(obj);
          }

          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }
      public ActionResult GetPatientWiseResultforParameterValue(int LabNo, int TestID)
      {
          List <Patient_Wise_Result_Entry> searclist = new List <Models.Laboratory.Patient_Wise_Result_Entry>();

          if (TestID > 0)
          {
              BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
              DataSet ds             = new DataSet();
              DataSet dsPatientEntry = new DataSet();
              DataSet dsCompare      = new DataSet();
              dsPatientEntry = BL_obj.GetPatientWiseResultforParameterValue(LabNo, TestID);
              dsCompare      = BL_obj.GetPatientWiseResultforParameterValue(Convert.ToInt32(LabNo), Convert.ToInt32(TestID));

              if (dsPatientEntry.Tables[0].Rows.Count > 0)
              {
                  if (dsPatientEntry.Tables[1].Rows[0]["TestStatus"].ToString().Trim() == "COMPLETED")
                  {
                      Patient_Wise_Result_Entry objc = new Patient_Wise_Result_Entry();

                      //  ucPatientWiseResultEntry1.gbDetail.Enabled = true;
                      //ucPatientWiseResultEntry1.dgvDetails.DataSource = dsPatientEntry.Tables[2];
                      //    ucPatientWiseResultEntry1.btnComplete.BackColor = Color.Green;
                      objc.Color = "Green";
                      searclist.Add(objc);

                      foreach (DataRow dr in dsPatientEntry.Tables[2].Rows)
                      {
                          Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                          //  dr["Formula"] = "5";
                          obj.UserID         = dr["UserID"].ToString();
                          obj.AuthoriserName = dr["AuthoriserName"].ToString();
                          obj.status         = dr["Status"].ToString();
                          obj.Remark         = dr["Remark"].ToString();
                          obj.LabNo          = dr["LabNo"].ToString();
                          obj.TestID         = dr["TestID"].ToString();
                          obj.TestName1      = dr["TestName"].ToString();


                          searclist.Add(obj);
                      }

                      foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
                      {
                          Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                          //  dr["Formula"] = "5";
                          obj.Formula       = dr["Formula"].ToString();
                          obj.LabNo         = dr["LabNo"].ToString();
                          obj.FullName      = dr["FullName"].ToString();
                          obj.NLH           = dr["NLH"].ToString();
                          obj.ParamiterName = dr["ParameterName"].ToString();
                          obj.Low           = dr["ConvLow"].ToString();
                          obj.Hiegh         = dr["ConvHigh"].ToString();
                          obj.ParamiterID   = dr["ParameterID"].ToString();
                          obj.status        = dr["Status"].ToString();
                          obj.TestID        = dr["TestID"].ToString();
                          obj.ResultValue   = dr["ResultValue"].ToString();
                          obj.Value1        = dr["Value1"].ToString();
                          obj.Value2        = dr["Value2"].ToString();
                          obj.Value3        = dr["Value3"].ToString();
                          obj.footer        = dr["Footer"].ToString();

                          //  obj.fo
                          searclist.Add(obj);
                      }
                  }
                  else
                  {
                      // ucPatientWiseResultEntry1.gbDetail.Enabled = false;
                      //   ucPatientWiseResultEntry1.btnComplete.BackColor = Color.Coral;
                      Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();

                      obj.Color = "Coral";
                      searclist.Add(obj);
                  }



                  // ucPatientWiseResultEntry1.dgvResultEntry.DataSource = dsPatientEntry.Tables[0];
                  //ucPatientWiseResultEntry1.dgvDetails.DataSource = dsPatientEntry.Tables[2];

                  if (dsPatientEntry.Tables[1].Rows[0]["TestStatus"].ToString().Trim() != "COMPLETED")
                  {
                      foreach (DataRow dr in dsPatientEntry.Tables[2].Rows)
                      {
                          Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                          //  dr["Formula"] = "5";
                          obj.UserID         = dr["UserID"].ToString();
                          obj.AuthoriserName = dr["AuthoriserName"].ToString();
                          obj.status         = dr["Status"].ToString();
                          obj.Remark         = dr["Remark"].ToString();
                          obj.LabNo          = dr["LabNo"].ToString();
                          obj.TestID         = dr["TestID"].ToString();
                          obj.TestName1      = dr["TestName"].ToString();

                          // obj.Color = "Green";
                          searclist.Add(obj);
                      }

                      foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
                      {
                          Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                          //  dr["Formula"] = "5";
                          obj.Formula       = dr["Formula"].ToString();
                          obj.LabNo         = dr["LabNo"].ToString();
                          obj.FullName      = dr["FullName"].ToString();
                          obj.NLH           = dr["NLH"].ToString();
                          obj.ParamiterName = dr["ParameterName"].ToString();
                          obj.Low           = dr["ConvLow"].ToString();
                          obj.Hiegh         = dr["ConvHigh"].ToString();
                          obj.ParamiterID   = dr["ParameterID"].ToString();
                          obj.status        = dr["Status"].ToString();
                          obj.TestID        = dr["TestID"].ToString();
                          obj.ResultValue   = dr["ResultValue"].ToString();
                          obj.Value1        = dr["Value1"].ToString();
                          obj.Value2        = dr["Value2"].ToString();
                          obj.Value3        = dr["Value3"].ToString();
                          obj.footer        = dr["FooterParameter"].ToString();

                          //  obj.fo
                          searclist.Add(obj);
                      }
                  }
              }
          }
          else
          {
              BL_Patient_Wise_Result_Entry BL_obj = new BL_Patient_Wise_Result_Entry();
              DataSet ds             = new DataSet();
              DataSet dsCompare      = new DataSet();
              DataSet dsPatientEntry = new DataSet();

              dsPatientEntry = BL_obj.GetPatientWiseResultforParameterValue(LabNo, TestID);
              dsCompare      = BL_obj.GetPatientWiseResultforParameterValue(Convert.ToInt32(LabNo), Convert.ToInt32(TestID));


              foreach (DataRow dr in dsPatientEntry.Tables[0].Rows)
              {
                  Patient_Wise_Result_Entry obj = new Patient_Wise_Result_Entry();
                  //  dr["Formula"] = "5";
                  obj.Formula       = dr["Formula"].ToString();
                  obj.LabNo         = dr["LabNo"].ToString();
                  obj.FullName      = dr["FullName"].ToString();
                  obj.NLH           = dr["NLH"].ToString();
                  obj.ParamiterName = dr["ParameterName"].ToString();
                  obj.Low           = dr["ConvLow"].ToString();
                  obj.Hiegh         = dr["ConvHigh"].ToString();
                  obj.ParamiterID   = dr["ParameterID"].ToString();
                  obj.status        = dr["Status"].ToString();
                  obj.TestID        = dr["TestID"].ToString();
                  obj.ResultValue   = "";
                  searclist.Add(obj);
              }
          }
          return(Json(searclist, JsonRequestBehavior.AllowGet));
      }