Отчет по прохождению учебной практики (вид практики учебной, производственной, преддипломной )



страница20/21
Дата30.06.2020
Размер0.98 Mb.
ТипОтчет
1   ...   13   14   15   16   17   18   19   20   21

ПРИЛОЖЕНИЕ 2. Презентация
























ПРИЛОЖЕНИЕ 3. Оптимизированный программный код

Код формы аутентификации




namespace Agent_Rielt

{

public partial class LoginForm : Form

{

SqlConnection sqlConnection;

public LoginForm()

{

InitializeComponent();

}
private void button1_Click(object sender, EventArgs e)

{

//string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\App_Data\Database1.mdf;Integrated Security=True";

//string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=E:\Agent_Rielt\Agent_Rielt\APP_DATA\Database1.mdf;Integrated Security=True";

string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\App_Data\Database1.mdf;Integrated Security=True";


sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();

SqlDataAdapter adapter = new SqlDataAdapter("SELECT COUNT(*) FROM [USERS] WHERE Login = '" + textBox1.Text + "'AND Password = '"+textBox2.Text + "'",sqlConnection);

DataTable dt = new DataTable();

adapter.Fill(dt);

if (dt.Rows[0][0].ToString() == "1")

{
MainForm form = new MainForm();

form.Show();

}

else

{

MessageBox.Show("Неверный Логин или Пароль");

}

sqlConnection.Close();
}
private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)

{

if (sqlConnection != null && sqlConnection.State != ConnectionState.Closed)

sqlConnection.Close();

}
private void LoginForm_Load(object sender, EventArgs e)

{
}

}

}

Код формы аутентификации


Код главной формы



namespace Agent_Rielt

{

public partial class MainForm : Form

{

public MainForm()

{

InitializeComponent();

}
private void button2_Click(object sender, EventArgs e)

{

ClientsForm form = new ClientsForm();

form.Show();

}
private void button1_Click(object sender, EventArgs e)

{

ObjectsForm form = new ObjectsForm();

form.Show();

}
private void button4_Click(object sender, EventArgs e)

{

Application.Exit();

}
private void button3_Click(object sender, EventArgs e)

{

SellsForm form = new SellsForm();

form.Show();

}
private void button5_Click(object sender, EventArgs e)

{

SellersForm form = new SellersForm();

form.Show();

}
private void MainForm_Load(object sender, EventArgs e)

{

LoginForm form = new LoginForm();

form.Close();

}

}

}



Код формы «Клиенты»
namespace Agent_Rielt

{

public partial class ClientsForm : Form

{

SqlConnection sqlConnection;
public ClientsForm()

{

InitializeComponent();

}
private void ClientsForm_Load(object sender, EventArgs e)

{
string connectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\App_Data\Database1.mdf;Integrated Security=True";

sqlConnection = new SqlConnection(connectionString);

sqlConnection.Open();
SqlDataReader sqlReader = null;
SqlCommand command = new SqlCommand("SELECT [Clients].*,[Sellers].ФИО_С FROM [Clients] JOIN [Sellers] ON [Clients].Seller_Id = Id", sqlConnection);
List<string[]> data = new List<string[]>();
try

{

sqlReader = command.ExecuteReader();
while (sqlReader.Read())

{

data.Add(new string[6]);

data[data.Count - 1][0] = sqlReader[0].ToString();

data[data.Count - 1][1] = sqlReader[1].ToString();

data[data.Count - 1][2] = sqlReader[2].ToString();

data[data.Count - 1][3] = sqlReader[3].ToString();

data[data.Count - 1][4] = sqlReader[4].ToString();

data[data.Count - 1][5] = sqlReader[5].ToString();

}
}

catch (Exception ex)

{

MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);

}

finally

{

sqlReader.Close();

}

foreach (string[] s in data)

dataGridView1.Rows.Add(s);

}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{
}
private void button1_Click(object sender, EventArgs e)

{

if (label9.Visible || label7.Visible){

label9.Visible = false;

label7.Visible = false;

}
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrWhiteSpace(textBox1.Text) &&

!string.IsNullOrEmpty(textBox5.Text) && !string.IsNullOrWhiteSpace(textBox5.Text) &&

!string.IsNullOrEmpty(textBox6.Text) && !string.IsNullOrWhiteSpace(textBox6.Text))

{

SqlCommand command = new SqlCommand("INSERT INTO [Clients] (Name, P_Number, Email, Pasport, Seller_Id) VALUES (@Name, @P_Number, @Email, @Pasport, @Seller_Id)", sqlConnection);

command.Parameters.AddWithValue("Name", textBox1.Text);

command.Parameters.AddWithValue("P_Number", textBox2.Text);

command.Parameters.AddWithValue("Email", textBox3.Text);

command.Parameters.AddWithValue("Pasport", textBox5.Text);

command.Parameters.AddWithValue("Seller_Id", textBox6.Text);
command.ExecuteNonQuery();

label7.Visible = true;

label7.Text = "Новый клиент успешно добавлен";


}

else

{

label9.Visible = true;

label9.Text = "Поля помеченные * обязательны для заполнения";

}

}
private void label9_Click(object sender, EventArgs e)

{
}
private void RefreshToolStripMenuItem_Click(object sender, EventArgs e)

{

dataGridView1.Rows.Clear();
SqlDataReader sqlReader = null;
SqlCommand command = new SqlCommand("SELECT [Clients].*,[Sellers].ФИО_С FROM [Clients] JOIN [Sellers] ON [Clients].Seller_Id = Id", sqlConnection);
List<string[]> data = new List<string[]>();

try

{

sqlReader = command.ExecuteReader();
while (sqlReader.Read())

{

data.Add(new string[6]);

data[data.Count - 1][0] = sqlReader[0].ToString();

data[data.Count - 1][1] = sqlReader[1].ToString();

data[data.Count - 1][2] = sqlReader[2].ToString();

data[data.Count - 1][3] = sqlReader[3].ToString();

data[data.Count - 1][4] = sqlReader[4].ToString();

data[data.Count - 1][5] = sqlReader[5].ToString();

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);

}

finally

{

sqlReader.Close();
}

foreach (string[] s in data)

dataGridView1.Rows.Add(s);
}
private void button3_Click(object sender, EventArgs e)

{
if (!string.IsNullOrEmpty(textBox12.Text) && !string.IsNullOrWhiteSpace(textBox12.Text) &&

!string.IsNullOrEmpty(textBox11.Text) && !string.IsNullOrWhiteSpace(textBox11.Text) &&

!string.IsNullOrEmpty(textBox10.Text) && !string.IsNullOrWhiteSpace(textBox10.Text) &&

!string.IsNullOrEmpty(textBox4.Text) && !string.IsNullOrWhiteSpace(textBox4.Text) &&

!string.IsNullOrEmpty(textBox8.Text) && !string.IsNullOrWhiteSpace(textBox8.Text))

{

SqlCommand command = new SqlCommand("UPDATE [Clients] SET [Name] = @Name, [P_Number] = @P_Number, [Email] = @Email, [Pasport] = @Pasport, [Seller_Id] = @Seller_Id WHERE [Id_C] = @Id_C",sqlConnection);
command.Parameters.AddWithValue("Id_C",textBox12.Text);

command.Parameters.AddWithValue("Name",textBox11.Text);

command.Parameters.AddWithValue("P_Number",textBox10.Text);

command.Parameters.AddWithValue("Email",textBox9.Text);

command.Parameters.AddWithValue("Pasport",textBox4.Text);

command.Parameters.AddWithValue("Seller_Id",textBox8.Text);

command.ExecuteNonQuery();
label8.Visible = true;

label8.Text = "Информация о клиенте изменена";

}

else

{

label10.Visible = true;

label10.Text = "Поля помеченные * обязательны для заполнения";

}

}
private void button2_Click(object sender, EventArgs e)

{
if (!string.IsNullOrEmpty(textBox7.Text) && !string.IsNullOrWhiteSpace(textBox7.Text))

{

SqlCommand command = new SqlCommand("DELETE FROM [Clients] WHERE [Id_C] = @Id_C", sqlConnection);

command.Parameters.AddWithValue("Id_C", textBox7.Text);

command.ExecuteNonQuery();
label20.Visible = true;

label20.Text = "Информация о клиенте удалена";
}

else

{

label19.Visible = true;

label19.Text = "Заполните поле 'ID'";

}

}
private void ClientsForm_FormClosing(object sender, FormClosingEventArgs e)

{

if (sqlConnection != null && sqlConnection.State != ConnectionState.Closed)

sqlConnection.Close();

}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

{
}

}

}


Поделитесь с Вашими друзьями:
1   ...   13   14   15   16   17   18   19   20   21




База данных защищена авторским правом ©zodorov.ru 2020
обратиться к администрации

    Главная страница