apéndice l. código de conexión a base de datos de usuarios

Anuncio
APÉNDICE L. CÓDIGO DE CONEXIÓN A BASE DE DATOS DE USUARIOS
//patientEdit.cs
//Autor: Luis Alberto Reyes Ramírez, 2009
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication4
{
public partial class patientEdit : Form
{
Random rand = new Random();
public
patientEdit()
{
InitializeComponent();
pictureBox1.Show(); pictureBox2.Hide(); pictureBox3.Hide();
pictureBox4.Hide(); pictureBox5.Hide();
}
private void patientEdit_Load(object sender, EventArgs e)
{
if (Form1.name != "Guest")
{
label5.Text = Form1.name;
label1.Text = "Sign Out";
pictureBox1.Hide();
}
for (Int32 i = 1; i < Form1.numberpatients + 1; i++)
{
Form1.dRow = Form1.ds1.Tables["elderly"].Rows[i - 1];
94
Apéndice L
95
comboBox2.Items.Add(Form1.dRow.ItemArray.GetValue(1).To
String());
}
if (Form1.numberpatients == 0) { }
else
Form1.dRow = Form1.ds1.Tables["elderly"].Rows[0];
}
public void showInfo()
{
//Table1
Form1.dRow =
Form1.ds1.Tables["elderly"].Rows[comboBox2.SelectedIndex];
//1
textBox1.Text = Form1.dRow.ItemArray.GetValue(1).ToString();
textBox2.Text = Form1.dRow.ItemArray.GetValue(2).ToString();
textBox3.Text = Form1.dRow.ItemArray.GetValue(3).ToString();
textBox4.Text = Form1.dRow.ItemArray.GetValue(4).ToString();
textBox5.Text = Form1.dRow.ItemArray.GetValue(5).ToString();
textBox6.Text = Form1.dRow.ItemArray.GetValue(6).ToString();
textBox7.Text = Form1.dRow.ItemArray.GetValue(7).ToString();
textBox8.Text = Form1.dRow.ItemArray.GetValue(1).ToString();
textBox9.Text = Form1.dRow.ItemArray.GetValue(2).ToString();
textBox10.Text = Form1.dRow.ItemArray.GetValue(3).ToString();
textBox11.Text = Form1.dRow.ItemArray.GetValue(4).ToString();
textBox12.Text = Form1.dRow.ItemArray.GetValue(5).ToString();
textBox13.Text = Form1.dRow.ItemArray.GetValue(6).ToString();
textBox14.Text = Form1.dRow.ItemArray.GetValue(7).ToString();
textBox15.Text = Form1.dRow.ItemArray.GetValue(1).ToString();
textBox16.Text = Form1.dRow.ItemArray.GetValue(2).ToString();
textBox17.Text = Form1.dRow.ItemArray.GetValue(3).ToString();
textBox18.Text = Form1.dRow.ItemArray.GetValue(4).ToString();
textBox19.Text = Form1.dRow.ItemArray.GetValue(5).ToString();
textBox20.Text = Form1.dRow.ItemArray.GetValue(6).ToString();
textBox21.Text = Form1.dRow.ItemArray.GetValue(7).ToString();
textBox22.Text = Form1.dRow.ItemArray.GetValue(8).ToString();
}
Apéndice L
96
public void createInfo()
{
System.Data.OleDb.OleDbCommandBuilder cb1;
cb1 = new System.Data.OleDb.OleDbCommandBuilder(Form1.da1);
DataRow dRow = Form1.ds1.Tables["elderly"].NewRow();
int a = rand.Next(400);
int b = rand.Next(50);
int c = rand.Next(1345);
dRow[0] = (a * b + c);
dRow[1] = textBox8.Text;
dRow[2] = textBox9.Text;
dRow[3] = textBox10.Text;
dRow[4] = textBox11.Text;
dRow[5] = textBox12.Text;
dRow[6] = textBox13.Text;
dRow[7] = textBox14.Text;
Form1.ds1.Tables["elderly"].Rows.Add(dRow);
Form1.da1.Update(Form1.ds1, "elderly");
Form1.numberpatients++;
}
public void editInfo()
{
System.Data.OleDb.OleDbCommandBuilder cb1;
cb1 = new System.Data.OleDb.OleDbCommandBuilder(Form1.da1);
Form1.dRow =
Form1.ds1.Tables["elderly"].Rows[comboBox2.SelectedIndex];
Form1.dRow[1] = textBox1.Text;
Form1.dRow[2] = textBox2.Text;
Form1.dRow[3] = textBox3.Text;
Form1.dRow[4] = textBox4.Text;
Form1.dRow[5] = textBox5.Text;
Form1.dRow[6] = textBox6.Text;
Form1.dRow[7] = textBox7.Text;
Form1.phone = Form1.dRow[7].ToString();
Apéndice L
97
Form1.da1.Update(Form1.ds1, "elderly");
}
private void label1_Click(object sender, EventArgs e)
{
pictureBox1.Show(); pictureBox2.Hide(); pictureBox3.Hide();
pictureBox4.Hide(); pictureBox5.Hide();
panel1.BringToFront();
comboBox2.Show();
if (label1.Text == "Sign In" && comboBox2.SelectedIndex != 1)
{
comboBox2.SelectedIndex = -1;
panel1.BringToFront();
}
if (label1.Text == "Sign Out")
{
comboBox2.SelectedIndex = -1;
panel1.BringToFront();
label1.Text = "Sign In";
label5.Text = "Guest";
Form1.name = label5.Text;
}
}
private void label2_Click(object sender, EventArgs e)
{
pictureBox1.Hide(); pictureBox2.Show(); pictureBox3.Hide();
pictureBox4.Hide(); pictureBox5.Hide();
comboBox2.Show();
comboBox2.SelectedIndex = -1;
panel2.BringToFront();
}
private void label3_Click(object sender, EventArgs e)
{
pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Show();
pictureBox4.Hide(); pictureBox5.Hide();
comboBox2.Hide();
label18.Show();
Apéndice L
98
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
textBox14.Text = "";
panel3.BringToFront();
}
private void label4_Click(object sender, EventArgs e)
{
pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Hide();
pictureBox4.Show(); pictureBox5.Hide();
comboBox2.SelectedIndex = -1;
comboBox2.Show();
label27.Show();
textBox15.Text = "";
textBox16.Text = "";
textBox17.Text = "";
textBox18.Text = "";
textBox19.Text = "";
textBox20.Text = "";
textBox21.Text = "";
panel4.BringToFront();
}
private void label36_Click(object sender, EventArgs e)
{
pictureBox1.Hide(); pictureBox2.Hide(); pictureBox3.Hide();
pictureBox4.Hide(); pictureBox5.Show();
comboBox2.Hide();
panel5.BringToFront();
}
private void label35_Click(object sender, EventArgs e)
{
Close();
}
private void label37_Click(object sender, EventArgs e)
Apéndice L
99
{
TextWriter tw = new StreamWriter("PatientData.txt");
tw.WriteLine("Hello World");
tw.Close();
System.Diagnostics.Process.Start("PatientData.txt");
}
private void label18_Click(object sender, EventArgs e)
{
//Create a new patient...
label18.Hide();
comboBox2.Items.Add(textBox8.Text);
createInfo();
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
textBox14.Text = "";
}
private void label27_Click(object sender, EventArgs e)
{
//Erase a patient...
if (comboBox2.SelectedIndex == -1) { }
else if (label5.Text == comboBox2.SelectedItem.ToString()) {
}
else
{
int patientindex = comboBox2.SelectedIndex;
comboBox2.Items.RemoveAt(patientindex);
System.Data.OleDb.OleDbCommandBuilder cb1;
cb1 = new
System.Data.OleDb.OleDbCommandBuilder(Form1.da1);
Form1.ds1.Tables["elderly"].Rows[patientindex].Delete();
Apéndice L
Form1.da1.Update(Form1.ds1, "elderly");
comboBox2.SelectedIndex = -1;
Form1.numberpatients--;
label27.Hide();
comboBox2.Items.Remove(comboBox2.SelectedItem);
comboBox2.SelectedIndex = -1;
textBox15.Text = "";
textBox16.Text = "";
textBox17.Text = "";
textBox18.Text = "";
textBox19.Text = "";
textBox20.Text = "";
textBox21.Text = "";
textBox22.Text = "";
}
}
private void label15_Click(object sender, EventArgs e)
{
//Edit
if (comboBox2.SelectedIndex == -1) { }
else
{
editInfo();
int selection = comboBox2.SelectedIndex;
comboBox2.Items.Insert(comboBox2.SelectedIndex,
textBox1.Text);
comboBox2.Items.RemoveAt(comboBox2.SelectedIndex);
comboBox2.SelectedIndex = selection;
if (label5.Text == "Guest") { }
else
{
label5.Text = textBox1.Text;
}
}
}
100
Apéndice L
101
private void label7_Click(object sender, EventArgs e)
{
//Select to sign in...
if (comboBox2.SelectedIndex == -1) { }
else
{
label1.Text = "Sign Out";
label5.Text = comboBox2.SelectedItem.ToString();
Form1.name = comboBox2.SelectedItem.ToString();
Form1.log = "";
Form1.dRow =
Form1.ds1.Tables["elderly"].Rows[comboBox2.SelectedInde
x];
//1
Form1.phone =
Form1.dRow.ItemArray.GetValue(7).ToString();
//Form1.textBox1.Text = "";
pictureBox1.Hide(); pictureBox2.Show();
pictureBox3.Hide(); pictureBox4.Hide();
pictureBox5.Hide();
panel2.BringToFront();
}
}
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
//When edit option changes
//if index = -1
if (comboBox2.SelectedIndex == -1)
{
textBox8.Text = "";
textBox9.Text = "";
textBox10.Text = "";
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
Apéndice L
textBox14.Text = "";
}
else
{
showInfo();
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
}
}
102
Descargar