Bai tap tong hop LINQ tham khao...........
Trang 1 trong tổng số 1 trang
Bai tap tong hop LINQ tham khao...........
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;
namespace QLBH
{
public partial class Form_login : Form
{
public Form_login()
{
InitializeComponent();
}
DataClasses_nccDataContext kt_login = new DataClasses_nccDataContext();
private void button_login_Click(object sender, EventArgs e)
{
string user = string.Empty;
string pass = string.Empty;
IQueryable<LOGIN> login = from lg in kt_login.LOGINs
where lg.username == textBox_user.Text && lg.password == textBox_pass.Text
select lg;
foreach (LOGIN log in login)
{
user = log.username;
pass = log.password;
}
if (user != "")
{
Main m = new Main();
m.Show();
textBox_user.Text = "";
textBox_pass.Text = "";
}
else
MessageBox.Show("Sai user va pass. Vui long nhap lai");
}
private void button_thoat_Click(object sender, EventArgs e)
{
Close();
}
}
}
-------------------------------------------------------------------------------
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;
namespace QLBH
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void cậpNhậtToolStripMenuItem_Click(object sender, EventArgs e)
{
NCC n = new NCC();
n.MdiParent = this;
n.Show();
}
private void tìmKiếmToolStripMenuItem_Click(object sender, EventArgs e)
{
TRACUU t = new TRACUU();
t.MdiParent = this;
t.Show();
}
private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Ban co chac thoat khong?", "Thong bao!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MessageBox.Show("Thoat thanh cong");
Close();
}
else
{
MessageBox.Show("Thoat khong thanh cong");
}
}
}
}
---------------------------------------------------------------------------------
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;
namespace QLBH
{
public partial class NCC : Form
{
public NCC()
{
InitializeComponent();
}
DataClasses_nccDataContext db = new DataClasses_nccDataContext();
private void NCC_Load(object sender, EventArgs e)
{
loadluoi();
dinhdangluoi();
}
void loadluoi()
{
var nhacc = from ncc in db.NHACCs
select new
{
ma = ncc.MANHACC,
ten = ncc.TENNHACC,
diachi = ncc.DIACHI,
dienthoai = ncc.DIENTHOAI
};
bindingSource1.DataSource = nhacc;
bindingNavigator1.BindingSource = bindingSource1;
dataGridView1.DataSource = bindingNavigator1.BindingSource;
}
private void dinhdangluoi()
{
dataGridView1.Columns[0].Width = 80;
dataGridView1.Columns[0].HeaderText = "MÃ NCC";
dataGridView1.Columns[1].Width = 100;
dataGridView1.Columns[1].HeaderText = "TÊN NCC";
dataGridView1.Columns[2].Width = 200;
dataGridView1.Columns[2].HeaderText = "ĐỊA CHỈ";
dataGridView1.Columns[3].Width = 100;
dataGridView1.Columns[3].HeaderText = "ĐIỆN THOẠI";
}
private void LoadTextBox()
{
textBox_mancc.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
textBox_tenncc.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
textBox_diachi.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
textBox_dienthoai.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
}
private int Xoa()
{
try
{
var nhacc = from ncc in db.NHACCs
where ncc.MANHACC == textBox_mancc.Text
select ncc;
db.NHACCs.DeleteAllOnSubmit(nhacc);
db.SubmitChanges();
return 1;
}
catch
{
return 0;
}
}
private int Sua()
{
try
{
NHACC nhacc = db.NHACCs.Single(ncc => ncc.MANHACC == textBox_mancc.Text);
nhacc.TENNHACC = textBox_tenncc.Text;
nhacc.DIACHI = textBox_diachi.Text;
nhacc.DIENTHOAI = textBox_dienthoai.Text;
db.SubmitChanges();
return 1;
}
catch
{
return 0;
}
}
private int Them()
{
try
{
NHACC nhacc = new NHACC();
nhacc.MANHACC = textBox_mancc.Text;
nhacc.TENNHACC = textBox_tenncc.Text;
nhacc.DIACHI = textBox_diachi.Text;
nhacc.DIENTHOAI = textBox_dienthoai.Text;
db.NHACCs.InsertOnSubmit(nhacc);
db.SubmitChanges();
return 1;
}
catch
{
return 0;
}
}
private void toolStripButton_xoa_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Ban co chac xoa khong?", "Thong bao!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (Xoa() == 1)
{
MessageBox.Show("Xoa thanh cong");
loadluoi();
LoadTextBox();
}
else
{
MessageBox.Show("Xoa khong thanh cong");
}
}
}
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
LoadTextBox();
}
private void toolStripButton_sua_Click(object sender, EventArgs e)
{
Sua();
loadluoi();
}
private void toolStripButton_them_Click(object sender, EventArgs e)
{
Them();
loadluoi();
}
private void toolStripButton_thoat_Click(object sender, EventArgs e)
{
//Close();
if (MessageBox.Show("Ban co chac thoat khong?", "Thong bao!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MessageBox.Show("Thoat thanh cong");
Close();
}
else
{
MessageBox.Show("Thoat khong thanh cong");
}
}
}
}
---------------------------------------------------------------------------------------------
TRONG CSDL SQL 2005
CREATE PROC SP_DDHTHEONGAYDH
@TUNGAY DATETIME,
@DENNGAY DATETIME
AS
SELECT SODH,CONVERT(CHAR(10),NGAYDH,103)AS NGAYDH,TENNHACC
FROM DONDH,NHACC
WHERE DONDH.MANHACC=NHACC.MANHACC AND
NGAYDH BETWEEN @TUNGAY AND @DENNGAY
CREATE PROC SP_DDHTHEONCC
@MANHACC CHAR(4)
AS
SELECT SODH,NGAYDH
FROM DONDH
WHERE MANHACC=@MANHACC
-----------------------------
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;
namespace QLBH
{
public partial class TRACUU : Form
{
public TRACUU()
{
InitializeComponent();
LoadComboxNCC();
}
DataClasses_nccDataContext db = new DataClasses_nccDataContext();
private void LoadComboxNCC()
{
var nhacc = from ncc in db.NHACCs
select ncc;
comboBox_ncc.DataSource = nhacc;
comboBox_ncc.ValueMember = "manhacc";
comboBox_ncc.DisplayMember = "tennhacc";
}
private void LoctheoNCC()
{
var dh = db.SP_DDHTHEONCC(comboBox_ncc.SelectedValue.ToString());
dataGridView1.DataSource = dh;
}
private void LoctheongayDH()
{
DateTime tungay = dateTimePicker_tungay.Value;
DateTime denngay = dateTimePicker_denngay.Value;
var dh = db.SP_DDHTHEONGAYDH(tungay, denngay);
dataGridView1.DataSource = dh;
}
private void button_xem_Click(object sender, EventArgs e)
{
if(radioButton_ncc.Checked)
{
LoctheoNCC();
}
if(radioButton_ngaydh.Checked)
{
LoctheongayDH();
}
}
}
}
Program.cs
-----------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace QLBH
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form_login());
}
}
}
Similar topics
» Đề tài tham khảo
» Tài Liệu LinQ nèk
» De thi CSDL Nang Cao (Tham khao)
» Tài liệu tham khảo học ATBMTT
» Tham khảo về code Java......
» Tài Liệu LinQ nèk
» De thi CSDL Nang Cao (Tham khao)
» Tài liệu tham khảo học ATBMTT
» Tham khảo về code Java......
Trang 1 trong tổng số 1 trang
Permissions in this forum:
Bạn không có quyền trả lời bài viết
|
|