You are on page 1of 3

‫ سمية التركــي‬/ ‫أ‬: ‫إعداد‬ ‫المحاضرة السابعة‬

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

namespace mm
{
public partial class Form10 : Form
{
public Form10()
{
InitializeComponent();
}

int flag = 0;
SqlCommandBuilder cb;
SqlConnection con = new SqlConnection("Data Source=desktop-3mai79e;Initial
Catalog=dept_db;Integrated Security=True");
SqlDataAdapter da1;
DataSet ds = new DataSet();
BindingSource bs = new BindingSource();

void dataload()
{
da1 = new SqlDataAdapter("select * from student_tab", con);
da1.Fill(ds, "std1");
bs.DataSource = ds;
cb = new SqlCommandBuilder(da1);
bs.DataMember = "std1";
dataGridView1.DataSource = bs;
textBox1.DataBindings.Add("text", bs, "st_id");
textBox2.DataBindings.Add("text", bs, "st_name");
radioButton1.DataBindings.Add("checked", bs, "st_sex", true);
dateTimePicker1.DataBindings.Add("text", bs, "st_date", true);
pictureBox1.DataBindings.Add("image", bs, "st_imag", true);
}
‫ سمية التركــي‬/ ‫أ‬: ‫إعداد‬ ‫المحاضرة السابعة‬

private void button8_Click(object sender, EventArgs e)


{
bs.Position--;
chrd();
}

private void button2_Click(object sender, EventArgs e)


{
bs.CancelEdit();
}

private void Form10_Load(object sender, EventArgs e)


{
dataload();
}
void chrd()
{
if (!radioButton1.Checked)
radioButton2.Checked = true;
}

private void button1_Click(object sender, EventArgs e)


{
openFileDialog1.Filter = "images |*.GIF;*.JPG;*.bmp;*.PNG|AII files(*.*) |*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}

private void save_Click(object sender, EventArgs e)


{

bs.EndEdit();
if (flag == 1)
da1.InsertCommand = cb.GetInsertCommand();
else
if (flag == 2)
da1.UpdateCommand = cb.GetUpdateCommand();
da1.Update(ds.Tables["std1"]);
flag = 0;

private void fir_Click(object sender, EventArgs e)


{
bs.MoveFirst();
chrd();
}

private void next_Click(object sender, EventArgs e)


{
bs.Position++;
chrd();

private void least_Click(object sender, EventArgs e)


{
bs.MoveLast();
chrd();
}
‫ سمية التركــي‬/ ‫أ‬: ‫إعداد‬ ‫المحاضرة السابعة‬

private void add_Click(object sender, EventArgs e)


{
bs.AddNew();
flag = 1;
radioButton2.Checked = true;
}

private void edit_Click(object sender, EventArgs e)


{
flag = 2;

private void del_Click(object sender, EventArgs e)


{
if (MessageBox.Show("‫"السجل؟ حذف تريد هل‬, "‫"حذف‬, MessageBoxButtons.YesNo) == DialogResult.Yes)
{
bs.Remove(bs.Current);
da1.DeleteCommand = cb.GetDeleteCommand();
da1.Update(ds.Tables["std1"]);
}
}
}
}

You might also like