Reja: I. Kirish visual C# haqida Microsoft Visual C# da konsol ilova dasturlar yaratish Microsoft Visual Studioda WinForm loyiha yaratish II. Asosiy qism
Talaba davomatini tekshirish uchun Form yaratib Kerakli kodlarni yozib olamiz
Download 1.64 Mb.
|
ibroximov
Talaba davomatini tekshirish uchun Form yaratib Kerakli kodlarni yozib olamiz
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; namespace mustaqil_ish { public partial class MainForm : MetroFramework.Forms.MetroForm { public int LoggedIn { get; set; } public int UserID { get; set; } public MainForm() { InitializeComponent(); LoggedIn = 0; } private void MainForm_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'dataSet1.AttendanceRecordsTBL' table. You can move, or remove it, as needed. this.attendanceRecordsTBLTableAdapter.Fill(this.dataSet1.AttendanceRecordsTBL); // TODO: This line of code loads data into the 'dataSet1.ClassesTBL' table. You can move, or remove it, as needed. this.classesTBLTableAdapter.Fill(this.dataSet1.ClassesTBL); MainForm aa = new MainForm(); Class_Data(); } #region Avtivated private void MainForm_Activated(object sender, EventArgs e) { if (LoggedIn == 1) { // Loginni ochish LoginForm newlogin = new LoginForm(); newlogin.ShowDialog(); if (newlogin.LoginFlag == true){ this.Show();} Else{ UserID = newlogin.UserID; statlbUser.Text = UserID.ToString(); LoggedIn = 1; } } } #endregion Activated private void metroButton3_Click(object sender, EventArgs e) { FrmAddClass addclass = new FrmAddClass(); addclass.UserID = this.UserID; addclass.ShowDialog(); } private void metroButton4_Click(object sender, EventArgs e) { StudentsFrm students = new StudentsFrm(); students.ClassName = metroComboBox1.Text; students.ClassID = (int)metroComboBox1.SelectedValue; students.ShowDialog(); } #region guna private void Class_Data() { guna2DataGridView1.Rows.Clear(); guna2DataGridView1.Rows.Add("123", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(5454S)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(.0.0CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); guna2DataGridView1.Rows.Add("BS(CS)", "ATI-AU-21", "Husanboy Ibraximov", "Amaliy matematika"); } #endregion private void pictureBox1_Click(object sender, EventArgs e){ Class_Data(); } private void pictureBox2_Click(object sender, EventArgs e) {} private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e) {} private void guna2DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {}}} 8-rasm Davomat olish oynasi 8- rasmda quyidagi kod ishga tushib natijamiz chiqadi va davomatni olishimiz mumkin. Biz kodlarimizni ishlashi uchun class yaratib boglab qoyamiz using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data.MySqlClient; using System.Data; using Olmosiy_System; namespace Transparent_Form { class StudentClass { DBconnect connect = new DBconnect(); public bool insertStudent(string fname, string lname, DateTime bdate, string gender, string phone, string address, byte[] img) { MySqlCommand command = new MySqlCommand("INSERT INTO `student`(`StdFirstName`, `StdLastName`, `Birthdate`, `Gender`, `Phone`, `Address`, `Photo`) VALUES(@fn, @ln, @bd, @gd, @ph, @adr, @img)", connect.getconnection); command.Parameters.Add("@fn", MySqlDbType.VarChar).Value = fname; command.Parameters.Add("@ln", MySqlDbType.VarChar).Value = lname; command.Parameters.Add("@bd", MySqlDbType.Date).Value = bdate; command.Parameters.Add("@gd", MySqlDbType.VarChar).Value = gender; command.Parameters.Add("@ph", MySqlDbType.VarChar).Value = phone; command.Parameters.Add("@adr", MySqlDbType.VarChar).Value = address; command.Parameters.Add("@img", MySqlDbType.Blob).Value = img; connect.openConnect(); if (command.ExecuteNonQuery() == 1) { connect.closeConnect(); return true; } else { connect.closeConnect(); return false; }} public DataTable getStudentlist(MySqlCommand command) { command.Connection = connect.getconnection; MySqlDataAdapter adapter = new MySqlDataAdapter(command); DataTable table = new DataTable(); adapter.Fill(table); return table; } public string exeCount(string query) { MySqlCommand command = new MySqlCommand(query, connect.getconnection); connect.openConnect(); string count = command.ExecuteScalar().ToString(); connect.closeConnect(); return count; } public string totalStudent() { return exeCount("SELECT COUNT(*) FROM student"); } public string maleStudent() { return exeCount("SELECT COUNT(*) FROM student WHERE `Gender`='Erkak'"); } public string femaleStudent() { return exeCount("SELECT COUNT(*) FROM student WHERE `Gender`='Ayol'"); } public DataTable searchStudent(string searchdata) { MySqlCommand command = new MySqlCommand("SELECT * FROM `student` WHERE CONCAT(`StdFirstName`,`StdLastName`,`Address`) LIKE '%" + searchdata + "%'", connect.getconnection); MySqlDataAdapter adapter = new MySqlDataAdapter(command); DataTable table = new DataTable(); adapter.Fill(table); return table; } public bool updateStudent(int id, string fname, string lname, DateTime bdate, string gender, string phone, string address, byte[] img) { MySqlCommand command = new MySqlCommand("UPDATE `student` SET `StdFirstName`=@fn,`StdLastName`=@ln,`Birthdate`=@bd,`Gender`=@gd,`Phone`=@ph,`Address`=@adr,`Photo`=@img WHERE `StdId`= @id", connect.getconnection); command.Parameters.Add("@id", MySqlDbType.Int32).Value = id; command.Parameters.Add("@fn", MySqlDbType.VarChar).Value = fname; command.Parameters.Add("@ln", MySqlDbType.VarChar).Value = lname; command.Parameters.Add("@bd", MySqlDbType.Date).Value = bdate; command.Parameters.Add("@gd", MySqlDbType.VarChar).Value = gender; command.Parameters.Add("@ph", MySqlDbType.VarChar).Value = phone; command.Parameters.Add("@adr", MySqlDbType.VarChar).Value = address; command.Parameters.Add("@img", MySqlDbType.Blob).Value = img; connect.openConnect(); if (command.ExecuteNonQuery() == 1) { connect.closeConnect(); return true; } else { connect.closeConnect(); return false; }} public bool deleteStudent(int id) { MySqlCommand command = new MySqlCommand("DELETE FROM `student` WHERE `StdId`=@id", connect.getconnection); command.Parameters.Add("@id", MySqlDbType.Int32).Value = id; connect.openConnect(); if (command.ExecuteNonQuery() == 1) { connect.closeConnect(); return true; } else { connect.closeConnect(); return false;}} public DataTable getList(MySqlCommand command){ command.Connection = connect.getconnection; MySqlDataAdapter adapter = new MySqlDataAdapter(command); DataTable table = new DataTable(); adapter.Fill(table); return table; } } } Yangi class yaratamiz va baza bilan boglash uchun ozimizga kerakli kodlarni kiritib olamiz using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MySql.Data.MySqlClient; namespace Olmosiy_System { internal class DBconnect { MySqlConnection connect = new MySqlConnection("datasource=localhost;port=3306;username=root;password=;database=studentdb"); public MySqlConnection getconnection { get { return connect; } } public void openConnect() { if (connect.State == System.Data.ConnectionState.Closed) connect.Open(); } //Create a fuction to close connection public void closeConnect() { if (connect.State == System.Data.ConnectionState.Open) connect.Close(); }}} Download 1.64 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling