Using System; using System. Collections. Generic

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;
namespace nazorat
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string login = textBox1.Text;
string password = textBox2.Text;
if(login == "" && password == "")
{
MessageBox.Show("Tizimga muafaqiyatli kirdingiz!!!");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
}
}
}
using System;
using System.Data;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using ConnectMySql;
namespace nazorat
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
DB dB = new DB();
MySqlDataAdapter adapter = new MySqlDataAdapter();
DataTable table = new DataTable();
MySqlCommand mySqlCommand = new MySqlCommand("SELECT id, Familiyasi, Ism, TugilganSana, Telefon, ElektronPochta, Guruhi FROM talabalar", dB.getConnection());
adapter.SelectCommand = mySqlCommand;
adapter.Fill(table);
try
{
dataGridView1.DataSource = table;
}
catch (Exception)
{
throw;
}
}
private void button2_Click(object sender, EventArgs e)
{
Form3 form3 = new Form3();
form3.Show();
this.Hide();
}
private void button3_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
int selectedIndex = dataGridView1.SelectedRows[0].Index;
if(dataGridView1.Rows[selectedIndex].Cells["id"].Value != null)
{
DB dB2 = new DB();
int studentIdToDelete = (int)dataGridView1.Rows[selectedIndex].Cells["id"].Value;
string query = "DELETE FROM talabalar WHERE id = @id";
MySqlCommand command = new MySqlCommand(query, dB2.getConnection());
command.Parameters.AddWithValue("@id", studentIdToDelete);
dB2.getConnection().Open();
int result = command.ExecuteNonQuery();
if (result > 0)
{
MessageBox.Show("Ma'lumot muvaffaqiyatli o'chirildi.");
}
else
{
MessageBox.Show("O'chirish amalga oshmadi.");
}
dB2.getConnection().Close();
dataGridView1.Rows.RemoveAt(selectedIndex);
}
}
else
{
MessageBox.Show("Qator tanlanmagan!");
}
}
}
}
using ConnectMySql;
using MySql.Data.MySqlClient;
using System;
using System.Windows.Forms;
namespace nazorat
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
DB dB3 = new DB();
string familyasi = textBox1.Text;
string ismi = textBox2.Text;
string tugulgansanasi = textBox3.Text;
string telefon = textBox4.Text;
string elekrtronpochta = textBox5.Text;
string guruhi = textBox6.Text;
string query = "INSERT INTO talabalar (Familiyasi, Ism, TugilganSana, Telefon, ElektronPochta, Guruhi) VALUES (@Familiyasi, @Ism, @TugilganSana, @Telefon, @ElektronPochta, @Guruhi);";
MySqlCommand command = new MySqlCommand(query, dB3.getConnection());
command.Parameters.AddWithValue("@Familiyasi", familyasi);
command.Parameters.AddWithValue("@Ism", ismi);
command.Parameters.AddWithValue("@TugilganSana", tugulgansanasi);
command.Parameters.AddWithValue("@Telefon", telefon);
command.Parameters.AddWithValue("@ElektronPochta", elekrtronpochta);
command.Parameters.AddWithValue("@Guruhi", guruhi);
dB3.getConnection().Open();
int result = command.ExecuteNonQuery();
dB3.getConnection().Close();
if (result > 0)
{
MessageBox.Show("Yangi talaba muvaffaqiyatli qo'shildi.");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
else
{
MessageBox.Show("Talaba qo'shishda xatolik yuz berdi.");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace ConnectMySql
{
internal class DB
{
MySqlConnection connection = new MySqlConnection("Server = localhost;port = 3306;username = yangi; password = 123456;database = oquvmarkaz");
public void openConnection()
{
if (connection.State == System.Data.ConnectionState.Closed)
connection.Open();
}
public void closeConnection()
{
if (connection.State == System.Data.ConnectionState.Open)
connection.Close();
}
public MySqlConnection getConnection()
{ return connection; }
}
}
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;
namespace masofadan_muloqot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string login = textBox1.Text;
string password = textBox2.Text;
if (login == "" && password == "")
{
MessageBox.Show("Tizimga kirdingiz!!!");
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
else MessageBox.Show("login yoki parol hato");
}
}
}
using System;
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace masofadan_muloqot
{
public partial class Form2 : Form
{
private TcpListener listener;
private TcpClient client;
private StreamReader STR;
private StreamWriter STW;
private string recieve;
private string textToSend;
public Form2()
{
InitializeComponent();
IPAddress[] localIP = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress address in localIP)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
ServerIPtextBox.Text = address.ToString();
}
}
}
private async void Startbutton_Click(object sender, EventArgs e)
{
TcpListener listener = new TcpListener(IPAddress.Any, int.Parse(textBox2.Text));
listener.Start();
client = await listener.AcceptTcpClientAsync();
ChatScreenTextBox.AppendText("Connected to Client" + "\n");
STR = new StreamReader(client.GetStream());
STW = new StreamWriter(client.GetStream()) { AutoFlush = true };
backgroundWorker1.RunWorkerAsync();
backgroundWorker2.WorkerSupportsCancellation = true;
}
private void Connectbutton_Click(object sender, EventArgs e)
{
client = new TcpClient();
IPEndPoint IpEnd = new IPEndPoint(IPAddress.Parse(ClientIPtextBox.Text), int.Parse(ClientPorttextBox.Text));
try
{
client.Connect(IpEnd);
ChatScreenTextBox.AppendText("Connected to Server" + "\n");
STW = new StreamWriter(client.GetStream()) { AutoFlush = true };
STR = new StreamReader(client.GetStream());
backgroundWorker1.RunWorkerAsync();
backgroundWorker2.WorkerSupportsCancellation = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
while (client.Connected)
{
try
{
recieve = STR.ReadLine();
if (recieve != null)
{
this.ChatScreenTextBox.Invoke(new MethodInvoker(delegate ()
{
ChatScreenTextBox.AppendText("Client: " + recieve + "\n");
}));
}
recieve = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
}
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{
if (client.Connected)
{
STW.WriteLine(textToSend);
this.ChatScreenTextBox.Invoke(new MethodInvoker(delegate ()
{
ChatScreenTextBox.AppendText("You: " + textToSend + "\n");
}));
}
else
{
MessageBox.Show("Sending Failed");
}
}
private void Sendbutton_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(MessagetextBox.Text))
{
textToSend = MessagetextBox.Text;
backgroundWorker2.RunWorkerAsync();
}
MessagetextBox.Text = "";
}
}
}
|