Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

how to bind each selected row to existing form in c# windows forms with sql server 2008

$
0
0

hi my name is vishal. Sorry for disturbing you people again.

i have created a dashboard using listview named lstDashItems control in c# windows forms with sql server 2008.

my dashboard contains the datas entered from each form.

i have defined a method updateUserActivities in mdi parent form.

the method contains following codes.

public void updateUserActivities(long refID, int ActType, string ActivityStr)
        {

            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            SqlCommand cmd = new SqlCommand("Insert into USERACTIVITIES(user_id,row_upd_date,activity,type,ref_id)" + "Values(@user_id,GetDate(),@activity,@type,@ref_id)", conn);
            conn.Open();
            {
                cmd.Parameters.AddWithValue("@user_id", pUserID);
                cmd.Parameters.AddWithValue("@activity", ActivityStr);
                cmd.Parameters.AddWithValue("@type", ActType);
                cmd.Parameters.AddWithValue("@ref_id", refID);
                cmd.ExecuteNonQuery();

            }
            conn.Close();


        }

where USERACTIVITIES is my table name.

design of USERACTIVITIES in sql server 2008

column name       datatype     AllowsNulls

user_id                   int              yes

row_upd_date      datetime     yes

activity                  varchar(50)   yes

type                      int                 yes

ref_id                  numeric(18,0)   yes

here is my coding of patient form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
namespace DRRS_in_Csharp
{
    public partial class Patient : Form
    {
        long pUserID = 1;
        long patientID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Patient()
        {
            InitializeComponent();
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            string SqlDataPull = ("Select doctor_first_name,doctor_last_name,doctor_middle_name from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id");
            SqlCommand cmd = new SqlCommand(SqlDataPull);
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                SqlDataPull = dr[0].ToString()+dr[1].ToString()+dr[2].ToString();
                cboDoctor.Items.Add(SqlDataPull);
            }
            dr.Close();
        }

        private void Patient_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;
            




        }

        public void loadPatient(string mpatientID)
        {
            button1.Text = "Save";
            SqlConnection conn = new SqlConnection(conString);

            string selectString = ("Select p.patient_id as patient_id,p.patient_dob as patient_dob,n.patient_first_name as patient_fname, n.patient_middle_name as patient_mname,n.patient_last_name as patient_lname,p.patient_sex as patient_sex, n.virology as virology,h.homenumber as homenumber,h.mobilenumber as mobilenumber,a.apartment_name as apartment_name,a.door_number as door_number,a.street_name_1 as street_name_1,a.street_name_2 as street_name_2,a.street_name_3 as street_name_3,a.village as village,a.city as city,a.State as State,a.country  as country,m.doctor_first_name+' '+m.doctor_middle_name+' '+m.doctor_last_name as doctor_name,a.apartment_number as apartment_number,a.pincode as pincode from PATIENT_NAME6 n,PATIENT_ID6 p,DOCTORDETAIL m,PATIENT_CONTACT6 h,ADDRESS7 a where n.patient_id=p.patient_id and a.patient_id=p.patient_id and p.patient_id=h.patient_id and p.patient_id=m.doctor_id and p.patient_id=@patientId");
            SqlDataAdapter adp = new SqlDataAdapter(selectString,conn);
            adp.SelectCommand.Parameters.Add("@patientId", SqlDbType.VarChar, 50);
            adp.SelectCommand.Parameters["@patientId"].Value = mpatientID;
            dataset = new DataSet();
            adp.Fill(dataset, "PATIENT_ID6");
            adp.Fill(dataset, "PATIENT_NAME6");
            adp.Fill(dataset, "ADDRESS7");
            adp.Fill(dataset, "PATIENT_CONTACT6");
            adp.Fill(dataset, "DOCTORDETAIL");

                dtDOB.DataBindings.Add("Text",dataset,"PATIENT_ID6.patient_dob");
                txtFname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_fname");
                txtMname.DataBindings.Add("Text",dataset,"PATIENT_NAME6.patient_mname");
                txtLname.DataBindings.Add("Text", dataset, "PATIENT_NAME6.patient_lname");
                cboSex.DataBindings.Add("Text", dataset, "PATIENT_ID6.patient_sex");
                cboVirology.DataBindings.Add("Text", dataset, "PATIENT_NAME6.virology");
                txtApartmentName.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_name");
                txtDoorNo.DataBindings.Add("Text", dataset, "ADDRESS7.door_number");
                txtStreet1.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_1");
                txtStreet2.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_2");
                txtStreet3.DataBindings.Add("Text", dataset, "ADDRESS7.street_name_3");
                txtVillageArea.DataBindings.Add("Text", dataset, "ADDRESS7.village");
                txtCity.DataBindings.Add("Text", dataset, "ADDRESS7.city");
                txtState.DataBindings.Add("Text", dataset, "ADDRESS7.State");
                txtCountry.DataBindings.Add("Text", dataset, "ADDRESS7.country");
                txtApartmentNo.DataBindings.Add("Text", dataset, "ADDRESS7.apartment_number");
                txtPostalCode.DataBindings.Add("Text", dataset, "ADDRESS7.pincode");
                txtHnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.homenumber");
                txtMnumber.DataBindings.Add("Text", dataset, "PATIENT_CONTACT6.mobilenumber");
                cboDoctor.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_name");
        }










        private void button1_Click(object sender, EventArgs e)
        {
            long patientID = 0;
            string dFieldName = "";
            Boolean vEmptyB=false;
            int vPatientID = 0;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "First Name should not be empty";
            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Sex should not be empty";
            }
            else if (cboVirology.SelectedIndex == -1)
            {
                vEmptyB=true;
                dFieldName = "Virology state of patient should not be empty";
            }
            else if (txtHnumber.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Home number of patient should not be empty";
            }
            if ((txtHnumber.Text.Length < 10) && (txtHnumber.Text.Length > 0))
            {
                vEmptyB = true;
                dFieldName = "Entered phone number was must have digits of ten numbers which includes extension code also";
                txtHnumber.Focus();
            }
            else if (txtCity.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "City of patient should not be empty";
            }
            else if (txtCountry.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Country of patient should not be empty";
            }
            else if (cboDoctor.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Doctor Name should not be empty";
            }
            if (vEmptyB==true)
            {
                MessageBox.Show(dFieldName+"should not be empty");
                return;
            }


            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd = new SqlCommand("Insert into PATIENT_ID6(patient_sex,patient_dob,row_upd_date,user_id)" + "Values(@patient_sex,@patient_dob,GetDate(),@user_id)", conn);
            if (patientID == 0)
            {
                if (cboSex.SelectedIndex == 0)
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "M";
                }
                else
                {
                    cmd.Parameters.AddWithValue("@patient_sex", SqlDbType.VarChar).Value = "F";
                }

                cmd.Parameters.AddWithValue("@patient_dob", dtDOB.Value.ToString("dd-MMM-yyyy"));
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }
            if (patientID > 0)
            {
                cmd = new SqlCommand("update PATIENT_NAME6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into PATIENT_NAME6(patient_first_name,patient_middle_name,patient_last_name,virology,row_upd_date,status,user_id)" + "Values(@patient_first_name,@patient_middle_name,@patient_last_name,@virology,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@patient_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@patient_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@patient_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@virology", cboVirology.SelectedIndex);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if ((txtHnumber.Text != "") || (txtMnumber.Text != ""))
            {
                if (patientID > 0)
                {
                    cmd = new SqlCommand("Update PATIENT_CONTACT6 set status=false where patient_id=" + patientID);
                }
                cmd = new SqlCommand("Insert into PATIENT_CONTACT6(homenumber,mobilenumber,status,row_upd_date,user_id)" + "Values(@homenumber,@mobilenumber,@status,GetDate(),@user_id)", conn);
                cmd.Parameters.AddWithValue("@homenumber", txtHnumber.Text);
                cmd.Parameters.AddWithValue("@mobilenumber", txtMnumber.Text);
                cmd.Parameters.AddWithValue("@status", true);
                cmd.Parameters.AddWithValue("@user_id", pUserID);

                cmd.ExecuteNonQuery();
            }
            
            if (patientID > 0)
            {
                cmd = new SqlCommand("Update ADDRESS7 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into ADDRESS7(apartment_name,door_number,street_name_1,street_name_2,street_name_3,village,city,state,country,row_upd_date,apartment_number,status,pincode,user_id)" + "Values(@apartment_name,@door_number,@street_name_1,@street_name_2,@street_name_3,@village,@city,@state,@country,GetDate(),@apartment_number,@status,@pincode,@user_id)", conn);
            cmd.Parameters.AddWithValue("@apartment_name", txtApartmentName.Text);
            cmd.Parameters.AddWithValue("@door_number", txtDoorNo.Text);
            cmd.Parameters.AddWithValue("@street_name_1", txtStreet1.Text);
            cmd.Parameters.AddWithValue("@street_name_2", txtStreet2.Text);
            cmd.Parameters.AddWithValue("@street_name_3", txtStreet3.Text);
            cmd.Parameters.AddWithValue("@village", txtVillageArea.Text);
            cmd.Parameters.AddWithValue("@city", txtCity.Text);
            cmd.Parameters.AddWithValue("@state", txtState.Text);
            cmd.Parameters.AddWithValue("@country", txtCountry.Text);
            cmd.Parameters.AddWithValue("@apartment_number", txtApartmentNo.Text);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@pincode", txtPostalCode.Text);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            if (patientID > 0)
            {
                cmd = new SqlCommand("Update DOCTORPATIENT6 set status=false where patient_id=" + patientID);
            }
            cmd = new SqlCommand("Insert into DOCTORPATIENT6(doctor_id,row_upd_date,status,user_id)" + "Values(@doctor_id,GetDate(),@status,@user_id)", conn);
            cmd.Parameters.AddWithValue("@doctor_id", cboDoctor.GetItemText(cboDoctor.SelectedIndex));
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();




            ((MDIParent5)this.MdiParent).updateUserActivities(vPatientID, 1, txtFname.Text + "Patient detail was added successfully");
            MessageBox.Show("Patient detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();
        }


here is the code of doctor form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DRRS_in_Csharp
{
    public partial class Doctor : Form
    {
        long doctorID;
        long pUserID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        public Doctor()
        {
            InitializeComponent();
        }
        public void loadDoctor(string mDoctorID)
        {
            button1.Text="Save";
            SqlConnection conn = new SqlConnection(conString);

            string selectString = ("Select p.doctor_id as doctor_id,p.doctor_dob as doctor_dob,n.doctor_first_name as doctor_fname, n.doctor_middle_name as doctor_mname,n.doctor_last_name as doctor_lname,p.doctor_sex as doctor_sex from DOCTORDETAIL n,DOCTOR3 p where n.doctor_id=p.doctor_id and p.doctor_id=@doctorId");
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
            dap.SelectCommand.Parameters.Add("@doctorId", SqlDbType.VarChar, 50);
            dap.SelectCommand.Parameters["@doctorId"].Value = mDoctorID;
            dataset = new DataSet();
            dap.Fill(dataset, "DOCTORDETAIL");
            dap.Fill(dataset, "DOCTOR3");
            txtFname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_fname");
            txtMname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_mname");
            txtLname.DataBindings.Add("Text", dataset, "DOCTORDETAIL.doctor_lname");
            cboSex.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_sex");
            dtDOB.DataBindings.Add("Text", dataset, "DOCTOR3.doctor_dob");


            
            
           

        }
        private void button1_Click(object sender, EventArgs e)
        {
            string dFieldName = "";
            Boolean vEmptyB = false;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "First name should not be empty";
            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Sex of doctor should not be empty";
            }
            if (vEmptyB==true)
            {
                MessageBox.Show(dFieldName + "should not be empty");
                return;
            }
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            if (doctorID == 0)
            {
                cmd = new SqlCommand("Insert into DOCTOR3(doctor_sex,doctor_dob,created_date,user_id)" + "Values(@doctor_sex,@doctor_dob,GetDate(),@user_id)", conn);
                if (cboSex.SelectedIndex == 0)
                {
                    cmd.Parameters.AddWithValue("@doctor_sex", SqlDbType.VarChar).Value = "M";
                }
                else
                {
                    cmd.Parameters.AddWithValue("@doctor_sex", SqlDbType.VarChar).Value = "F";
                }
                cmd.Parameters.AddWithValue("@doctor_dob", dtDOB.Value);
                cmd.Parameters.AddWithValue("@user_id", pUserID);
                cmd.ExecuteNonQuery();
            }
            if (doctorID == 0)
            {
                cmd = new SqlCommand("Update DOCTORDETAIL set status=false where doctor_id=" + doctorID);
            }
            cmd = new SqlCommand("Insert into DOCTORDETAIL(doctor_first_name,doctor_middle_name,doctor_last_name,status,row_upd_date,user_id)" + "Values(@doctor_first_name,@doctor_middle_name,@doctor_last_name,@status,GetDate(),@user_id)", conn);
            cmd.Parameters.AddWithValue("@doctor_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@doctor_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@doctor_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();



            ((MDIParent5)this.MdiParent).updateUserActivities(pUserID, 2, txtFname.Text + "doctor detail was added successfully");
            MessageBox.Show("Doctor Detail was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();

        }

here is the code of technician form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace DRRS_in_Csharp
{
    public partial class Technician : Form
    {
        long pUserID;
        private string conString = "Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true";
        private DataSet dataset;
        private string selectString = "Select td.technician_first_name,td.technician_middle_name,td.technician_last_name,t.technician_dob,t.technician_sex,td.technician_type from TECHNICIANDETAIL6 td,TECHNICIAN6 t where td.technician_id=t.technician_id";
        public Technician()
        {
            InitializeComponent();

        }

        private void Technician_Load(object sender, EventArgs e)
        {
            dtDOB.MaxDate = dtDOB.Value;
            SqlConnection conn = new SqlConnection(conString);
            SqlDataAdapter dap = new SqlDataAdapter(selectString, conn);
                dataset = new DataSet();
                dap.Fill(dataset, "TECHNICIANDETAIL6");
                dap.Fill(dataset, "TECHNICIAN6");
                this.label11.Text = "Record :     " + ((this.BindingContext[dataset, "TECHNICIANDETAIL6"].Position + 1).ToString());
                this.label11.Text = "Record :        " + ((this.BindingContext[dataset, "TECHNICIAN6"].Position + 1).ToString());
                this.txtFname.DataBindings.Add("Text", dataset, "TECHNICIANDETAIL6.technician_first_name");
                this.txtMname.DataBindings.Add("Text", dataset, "TECHNICIANDETAIL6.technician_middle_name");
                this.txtLname.DataBindings.Add("Text", dataset, "TECHNICIANDETAIL6.technician_last_name");
                this.cboTechType.DataBindings.Add("Text", dataset, "TECHNICIANDETAIL6.technician_type");
                this.cboSex.DataBindings.Add("Text", dataset, "TECHNICIAN6.technician_sex");
                this.dtDOB.DataBindings.Add("Text", dataset, "TECHNICIAN6.technician_dob");
                this.trackBar2.Maximum = this.BindingContext[dataset, "TECHNICIANDETAIL6"].Count - 1;
                this.trackBar2.Maximum = this.BindingContext[dataset, "TECHNICIAN6"].Count - 1;
            }
        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "New")
            {
                txtFname.Enabled = true;
                txtMname.Enabled = true;
                txtLname.Enabled = true;
                cboSex.Enabled = true;
                dtDOB.Enabled = true;
                cboTechType.Enabled = true;

                txtFname.Text = "";
                txtMname.Text = "";
                txtLname.Text = "";
                cboSex.SelectedIndex = -1;
                txtFname.Focus();
                button1.Text = "Create";
            }
            string dFieldName = "";
            Boolean vEmptyB = false;
            if (txtFname.Text.ToString().Trim() == "")
            {
                vEmptyB = true;
                dFieldName = "Please enter the technician first name";
            }
            else if (cboSex.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Please select gender for technician";
            }
            else if (cboTechType.SelectedIndex == -1)
            {
                vEmptyB = true;
                dFieldName = "Please select technician type";
            }
            if (vEmptyB == true)
            {
                MessageBox.Show(dFieldName + "should not be empty");
                return;
            }
            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            cmd = new SqlCommand("insert into TECHNICIAN6(technician_dob,technician_sex,row_upd_date,user_id)" + "Values(@technician_dob,@technician_sex,GetDate(),@user_id)", conn);
            if (cboSex.SelectedIndex == 0)
            {
                cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "MALE";
            }
            else
            {
                cmd.Parameters.AddWithValue("@technician_sex", SqlDbType.VarChar).Value = "FEMALE";
            }
            cmd.Parameters.AddWithValue("@technician_dob", dtDOB.Value);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();

            cmd = new SqlCommand("Insert into TECHNICIANDETAIL6(technician_first_name,technician_middle_name,technician_last_name,row_upd_date,status,user_id,technician_type)" + "Values(@technician_first_name,@technician_middle_name,@technician_last_name,GetDate(),@status,@user_id,@technician_type)", conn);
            cmd.Parameters.AddWithValue("@technician_first_name", txtFname.Text);
            cmd.Parameters.AddWithValue("@technician_middle_name", txtMname.Text);
            cmd.Parameters.AddWithValue("@technician_last_name", txtLname.Text);
            cmd.Parameters.AddWithValue("@technician_type", cboTechType.SelectedIndex);
            cmd.Parameters.AddWithValue("@status", true);
            cmd.Parameters.AddWithValue("@user_id", pUserID);
            cmd.ExecuteNonQuery();
            ((MDIParent5)this.MdiParent).updateUserActivities(pUserID, 3, txtFname.Text + "technician detail was added successfully");
            MessageBox.Show("Technician detail  was added successfully", "DRRS", MessageBoxButtons.OK, MessageBoxIcon.Information);
            conn.Close();
            this.Close();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            txtFname.Enabled = false;
            txtMname.Enabled = false;
            txtLname.Enabled = false;
            cboTechType.Enabled = false;
            cboSex.Enabled = false;
            dtDOB.Enabled = false;
           
            this.BindingContext[dataset, "TECHNICIANDETAIL6"].Position = trackBar2.Value;
            this.BindingContext[dataset, "TECHNICIAN6"].Position = trackBar2.Value;
            label11.Text="Record:       "+((this.BindingContext[dataset,"TECHNICIANDETAIL6"].Position+1).ToString());
            label11.Text = "Record:       " + ((this.BindingContext[dataset, "TECHNICIAN6"].Position + 1).ToString());
           if ((this.BindingContext[dataset, "TECHNICIANDETAIL6"].Position ) < (this.BindingContext[dataset, "TECHNICIANDETAIL6"].Count-1))
           {
               this.BindingContext[dataset,"TECHNICIANDETAIL6"].Position+=1;
           }
            else
           {
                ShowMessageboxService.fnShowMessageBoxWithParameters("You´ve reached the end of the records","LAST RECORD",
						   MessageBoxButtons.OK,
						   MessageBoxIcon.Information,0,0);	
           }
           if ((this.BindingContext[dataset, "TECHNICIAN6"].Position) < (this.BindingContext[dataset, "TECHNICIAN6"].Count - 1))
           {
               this.BindingContext[dataset, "TECHNICIAN6"].Position += 1;
           }
           else
           {
               ShowMessageboxService.fnShowMessageBoxWithParameters("You've reached the end of the records","LAST RECORD",
                   MessageBoxButtons.OK,
                   MessageBoxIcon.Information, 0, 0);
           }
            if(this.BindingContext[dataset,"TECHNICIANDETAIL6"].Position==1)
            {
                ShowMessageboxService.fnShowMessageBoxWithParameters("You've reached the beginning of records","FIRST RECORD",
                    MessageBoxButtons.OK,
		  MessageBoxIcon.Information,0,0);
        }
            if (this.BindingContext[dataset, "TECHNICIAN6"].Position == 1)
            {
                ShowMessageboxService.fnShowMessageBoxWithParameters("You've reached the beginning of records","FIRST RECORD",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information, 0, 0);
            }

       

        





        }

now in my dashboard form i have populated listview named lstDashItems using following code and it works:

            SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=Tuscan46;Integrated Security=true");
            lstDashItems.Items.Clear();
            DataTable dt = new DataTable();
            SqlCommand cmd = new SqlCommand();
            DataSet ds;
            SqlDataAdapter adp = new SqlDataAdapter();
            cmd = new SqlCommand("Select * from USERACTIVITIES where user_id=" + pUserID + "Order by row_upd_date desc", conn);
            adp = new SqlDataAdapter(cmd);
            ds = new DataSet();
            adp.Fill(ds, "USERACTIVITIES");
            dt = ds.Tables["USERACTIVITIES"];
            lstDashItems.Columns.Add("Task", 340, HorizontalAlignment.Left);
            lstDashItems.Columns.Add("Date", 492, HorizontalAlignment.Right);
            lstDashItems.View = View.Details;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                lstDashItems.Items.Add(dt.Rows[i].ItemArray[2].ToString());
                lstDashItems.Items[i].SubItems.Add(dt.Rows[i].ItemArray[1].ToString());
            }

i have enabled fullrowselect property in my listview.

now the tricky part is when my form(windows forms) named DashBoard.cs loads it contains all the datas that have been entered in each forms. So lots of rows appear.

i have enabled double click event of my listview in below following code

this.lstDashItems.DoubleClick += new System.EventHandler(this.lstDashItems_DoubleClick)

What i want is when user double clicks a row from listview(patient data or doctor data or technician data) it should go respective form with their data.

Now i know i have done it with your people help for single row in listview but i dont know how to do with multiple rows in listview.

Now i know i could put if condition in terms of selecting form. The type field in USERACTIVITIES table contains values(1 for patient data,2 for doctor data and 3 for technician data).

Now i know i could type field value in if condition in terms of selecting respective forms. But i dont know how to do it or i am confused on how to use type field value from USERACTIVITIES table in if condition in DashBoard.cs windows forms.

Can anyone help me please? i am going nuts over this problem. Any help or guidance would be greatly appreciated.



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>