public bool AddDoctorReschedule(KeystoneProject.Models.Patient.PatientAppointmentSchedule obj)
        {
            Connect();
            con.Open();
            SqlCommand cmd = new SqlCommand("IUDoctorReschedule", con);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@HospitalID", HospitalID);
            cmd.Parameters.AddWithValue("@LocationID", LocationID);
            if (obj.RescheduleID != null)
            {
                cmd.Parameters.AddWithValue("@RescheduleID", 0);
                cmd.Parameters["@RescheduleID"].Direction = ParameterDirection.Output;
            }
            else
            {
                cmd.Parameters.AddWithValue("@RescheduleID", obj.RescheduleID);
            }

            cmd.Parameters.AddWithValue("@Reason", obj.Reason);
            cmd.Parameters.AddWithValue("@DoctorID", obj.DoctorID);
            cmd.Parameters.AddWithValue("@DoctorName", obj.DoctorName);

            cmd.Parameters.AddWithValue("@DoctorAppointmentScheduleID", 0);


            cmd.Parameters.AddWithValue("@PatientAppointmentID", 0);
            //  if(obj.)
            cmd.Parameters.AddWithValue("@CancelAppointment", obj.CancelAppointment);
            cmd.Parameters.AddWithValue("@FromTime", obj.FromTime);
            cmd.Parameters.AddWithValue("@ToTime", obj.ToTime);
            cmd.Parameters.AddWithValue("@AppointmentType", obj.AppointmentType);
            cmd.Parameters.AddWithValue("@Date", obj.Date);

            cmd.Parameters.AddWithValue("@CreationID", UserID);
            cmd.Parameters.AddWithValue("@Mode", "Add");
            int i = cmd.ExecuteNonQuery();

            con.Close();
            return(true);
        }
        public bool Save(KeystoneProject.Models.Patient.PatientAppointmentSchedule obj, DataSet ds)
        {
            Connect();

            con.Open();

            SqlCommand cmd = new SqlCommand("IUPatientAppointment", con);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@HospitalID", HospitalID);
            cmd.Parameters.AddWithValue("@LocationID", LocationID);
            cmd.Parameters.AddWithValue("@PFPatientName", obj.PFPatientName);
            if (obj.PatientID == null || obj.PatientID == "" || obj.PatientID == "0")
            {
                cmd.Parameters.AddWithValue("@PatientID", 0);
                cmd.Parameters["@PatientID"].Direction = ParameterDirection.Output;
                cmd.Parameters.AddWithValue("@Mode", "Add");
            }
            else
            {
                cmd.Parameters.AddWithValue("@PatientID", obj.PatientID);
                cmd.Parameters.AddWithValue("@Mode", "Edit");
            }

            cmd.Parameters.AddWithValue("@PatientRegNo", 0);
            cmd.Parameters.AddWithValue("@PatientName", (obj.FirstName + " " + obj.PMiddleName + " " + obj.PLastName).ToUpper());
            if (obj.FirstName == null)
            {
                cmd.Parameters.AddWithValue("@PFirstName", "");
            }
            else
            {
                cmd.Parameters.AddWithValue("@PFirstName", obj.FirstName.ToUpper());
            }
            if (obj.PMiddleName != null)
            {
                cmd.Parameters.AddWithValue("@PMiddleName", obj.PMiddleName.ToUpper());
            }
            else
            {
                cmd.Parameters.AddWithValue("@PMiddleName", "");
            }
            if (obj.PLastName != null)
            {
                cmd.Parameters.AddWithValue("@PLastName", obj.PLastName.ToUpper());
            }
            else
            {
                cmd.Parameters.AddWithValue("@PLastName", "");
            }

            if (obj.Gender != null)
            {
                cmd.Parameters.AddWithValue("@Gender", obj.Gender);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Gender", "");
            }

            if (obj.Age != null)
            {
                cmd.Parameters.AddWithValue("@Age", obj.Age);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Age", 0);
            }
            cmd.Parameters.AddWithValue("@AgeType", "Years");
            cmd.Parameters.AddWithValue("@DateOfBirth", obj.DateOFBirth);

            cmd.Parameters.AddWithValue("@MobileNo", obj.MobileNo);
            cmd.Parameters.AddWithValue("@PatientStatus", 0);

            cmd.Parameters.AddWithValue("@CreationID", UserID);
            int PatientID = cmd.ExecuteNonQuery();

            obj.PatientID = cmd.Parameters["@PatientID"].Value.ToString();

            // int i = cmd.ExecuteNonQuery();
            var delimiters = new char[] { 'T', 'o' };
            var results    = obj.FromTime.Split(delimiters);
            // string[] datefo=obj.FromTime.Split(p);

            SqlCommand cmd1 = new SqlCommand("[IUPatientAppointmentDetails]", con);

            cmd1.CommandType = CommandType.StoredProcedure;

            cmd1.Parameters.AddWithValue("@HospitalID", HospitalID);
            cmd1.Parameters.AddWithValue("@LocationID", LocationID);
            cmd1.Parameters.AddWithValue("@PatientRegNo", 0);


            if (obj.PatientAppointmentScheduleID == null || obj.PatientAppointmentScheduleID == "")
            {
                cmd1.Parameters.AddWithValue("@PatientAppointmentScheduleID", 0);
                cmd1.Parameters["@PatientAppointmentScheduleID"].Direction = ParameterDirection.Output;
                cmd1.Parameters.AddWithValue("@Mode", "Add");
            }
            else
            {
                cmd1.Parameters.AddWithValue("@PatientAppointmentScheduleID", obj.PatientAppointmentScheduleID);
                cmd1.Parameters.AddWithValue("@Mode", "Edit");
            }



            //   cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", obj.DoctorAppoinmentScheduleID);
            cmd1.Parameters.AddWithValue("@PatientID", obj.PatientID);

            cmd1.Parameters.AddWithValue("@DoctorID", obj.DoctorID);
            if (obj.AppointmentDate == null)
            {
                cmd1.Parameters.AddWithValue("@AppointmentDate", System.DateTime.Now);
            }
            else
            {
                cmd1.Parameters.AddWithValue("@AppointmentDate", Convert.ToDateTime(obj.AppointDateID));
            }

            if (obj.AppointmentType != "OnCalls")
            {
                DataView dvDetail = new DataView(ds.Tables[0], "NoOfAppointment = '" + obj.AppointmentNoID + "' ", "", DataViewRowState.CurrentRows);
                if (dvDetail.Count > 0)
                {
                    cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", dvDetail[0]["DoctorAppoinmentScheduleID"].ToString());
                    cmd1.Parameters.AddWithValue("@FromTime", dvDetail[0]["FromTime"].ToString());
                    cmd1.Parameters.AddWithValue("@ToTime", dvDetail[0]["ToTime"].ToString());
                    cmd1.Parameters.AddWithValue("@NoOfAppointment", dvDetail[0]["NoOfAppointment"].ToString());
                }
                else
                {
                    if (ds.Tables[0].Rows[0]["DoctorAppoinmentScheduleID"].ToString() == "")
                    {
                        cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", ds.Tables[0].Rows[0]["DoctorAppoinmentScheduleID"].ToString());
                    }
                    else
                    {
                        cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", obj.DoctorAppoinmentScheduleID);
                    }
                    if (obj.FromTime == "")
                    {
                        cmd1.Parameters.AddWithValue("@FromTime", "");
                    }
                    else
                    {
                        cmd1.Parameters.AddWithValue("@FromTime", obj.FromTime);
                    }
                    if (obj.ToTime == "")
                    {
                        cmd1.Parameters.AddWithValue("@ToTime", "");
                    }
                    else
                    {
                        cmd1.Parameters.AddWithValue("@ToTime", obj.ToTime);
                    }
                    cmd1.Parameters.AddWithValue("@NoOfAppointment", obj.AppointmentNoID);
                }
            }
            else
            {
                if (ds.Tables[0].Rows[0]["DoctorAppoinmentScheduleID"].ToString() == "")
                {
                    cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", ds.Tables[0].Rows[0]["DoctorAppoinmentScheduleID"].ToString());
                }
                else
                {
                    cmd1.Parameters.AddWithValue("@DoctorAppoinmentScheduleID", "");
                }
                if (obj.FromTime == "")
                {
                    cmd1.Parameters.AddWithValue("@FromTime", obj.FromTime);
                }
                else
                {
                    cmd1.Parameters.AddWithValue("@FromTime", "");
                }
                if (obj.ToTime == "")
                {
                    cmd1.Parameters.AddWithValue("@ToTime", obj.ToTime);
                }
                else
                {
                    cmd1.Parameters.AddWithValue("@ToTime", "");
                }
                cmd1.Parameters.AddWithValue("@NoOfAppointment", 0);
            }
            cmd1.Parameters.AddWithValue("@CreationID", UserID);


            //cmd1.Parameters.AddWithValue("@AppointmentType", obj.AppointmentType);

            //cmd1.Parameters.AddWithValue("@FromTime", results[0]);
            //cmd1.Parameters.AddWithValue("@ToTime", results[2]);
            //cmd1.Parameters.AddWithValue("@NoOfAppointment", obj.AppointmentNoID);

            //cmd1.Parameters.AddWithValue("@CreationID", UserID);

            int Vouchar = cmd1.ExecuteNonQuery();



            con.Close();
            return(true);
        }