Tải bản đầy đủ (.doc) (13 trang)

MÃ PHẦN mềm QUẢN lý hộ KHẨU c PHẦN 2

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (231.83 KB, 13 trang )

MÃ VIẾT PHẦN MỀM QUẢN LÝ HỘ KHẨU
BẰNG C# PHẦN 2
1. mã phần nhập dữ liệu

2. Phần chuyển đi

Code phần chuyển đi:
1


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Drawing;
using System.Linq;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
namespace vidu5
{
public partial class Chuyen_di : Form
{
DataTable dt;
DataView dw;
OleDbDataAdapter da;
//=================
public OleDbConnection mycon;


public OleDbDataAdapter myda;
public DataSet myds;
public DataTable mydt;
Data dtc = new Data();
PrintDocument document = new PrintDocument();
PrintPreviewDialog xemin = new PrintPreviewDialog();
public Chuyen_di()
{
InitializeComponent();
document.PrintPage += new
PrintPageEventHandler(document_PrintPage);
}
private void Chuyen_di_Load(object sender, EventArgs e)
2


{
dtc.ketnoi();
//=====================
tngay.Text = Get_Day();
tthang.Text = Get_Month();
txtnam.Text = Get_Year();
this.CenterToScreen();// canh giữa màn hình
btnchuyen.Enabled = false;
btn_in.Enabled = false;
}
protected override void WndProc(ref Message m)
{
const int WM_NCLBUTTONDOWN = 161;
const int WM_SYSCOMMAND = 274;

const int HTCAPTION = 2;
const int SC_MOVE = 61456;
if ((m.Msg == WM_SYSCOMMAND) && (m.WParam.ToInt32()
== SC_MOVE))
{
return;
}
if ((m.Msg == WM_NCLBUTTONDOWN) &&
(m.WParam.ToInt32() == HTCAPTION))
{
return;
}
base.WndProc(ref m);
}
//=================định dạng ngày tháng hiện tại trong texbox
public string Get_Day()
{
string str = DateTime.Now.ToString().Trim();
str = str.Substring(0, 2);
return str;
}
public string Get_Month()
3


{
string str = DateTime.Now.ToString().Trim();
str = str.Substring(3, 2);
return str;
}

public string Get_Year()
{
string str = DateTime.Now.ToString().Trim();
str = str.Substring(6, 4);
return str;
}
//==========================

void document_PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(LCAH.Text, new Font("Times New Roman",
14, FontStyle.Regular), Brushes.Black, 50, 100);
e.Graphics.DrawString(LCAX.Text, new Font("Times New Roman",
14, FontStyle.Bold), Brushes.Black, 55, 120);
e.Graphics.DrawString(lchxh.Text, new Font("Times New Roman",
14, FontStyle.Bold), Brushes.Black, 350, 100);
e.Graphics.DrawString(ldl.Text, new Font("Times New Roman", 14,
FontStyle.Bold), Brushes.Black, 410, 120);

//==================================
e.Graphics.DrawString(lso.Text, new Font("Times New Roman", 14,
FontStyle.Bold), Brushes.Black, 100, 150);
e.Graphics.DrawString(txtso.Text, new Font("Times New Roman",
14, FontStyle.Bold), Brushes.Black, 130, 150);
e.Graphics.DrawString(lgchk.Text, new Font("Times New Roman",
14, FontStyle.Bold), Brushes.Black, 170, 150);
//===============================

4



e.Graphics.DrawString(L_gchk.Text, new Font("Times New
Roman", 14, FontStyle.Bold), Brushes.Black, 270, 200);
//====================
e.Graphics.DrawString(l1.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 300);
e.Graphics.DrawString(t1.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 200, 300);
e.Graphics.DrawString(l2.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 500, 300);
e.Graphics.DrawString(t2.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 650, 300);
//============================
e.Graphics.DrawString(l3.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 330);
e.Graphics.DrawString(t3.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 350, 330);
//======================
e.Graphics.DrawString(l4.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 360);
e.Graphics.DrawString(t4.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 300, 360);
//=========================
e.Graphics.DrawString(l5.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 390);
e.Graphics.DrawString(t5.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 200, 390);
//=========================
e.Graphics.DrawString(l6.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 420);

e.Graphics.DrawString(t6.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 164, 420);
e.Graphics.DrawString(l7.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 280, 420);
e.Graphics.DrawString(t7.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 400, 420);
//======================
e.Graphics.DrawString(l8.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 450);
e.Graphics.DrawString(t8.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 160, 450);
5


e.Graphics.DrawString(l9.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 280, 450);
e.Graphics.DrawString(t9.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 400, 450);
e.Graphics.DrawString(l10.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 550, 450);
e.Graphics.DrawString(t10.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 700, 450);
//=======================
e.Graphics.DrawString(l11.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 480);
e.Graphics.DrawString(t11.Text, new Font("Times New Roman", 12,
FontStyle.Regular), Brushes.Black, 230, 480);
e.Graphics.DrawString(tap.Text, new Font("Times New Roman", 12,
FontStyle.Regular), Brushes.Black, 295, 480);
e.Graphics.DrawString(txht.Text, new Font("Times New Roman",

12, FontStyle.Regular), Brushes.Black, 430, 480);
//=======================
e.Graphics.DrawString(l12.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 510);
e.Graphics.DrawString(t12.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 240, 510);
//========================
e.Graphics.DrawString(l13.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 540);
e.Graphics.DrawString(t13.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 240, 540);
//======================
e.Graphics.DrawString(l14.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 570);
e.Graphics.DrawString(t14.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 300, 570);
//=========================
e.Graphics.DrawString(l15.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 600);
e.Graphics.DrawString(t15.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 240, 600);
//=================
e.Graphics.DrawString(l16.Text, new Font("Times New Roman", 14,
FontStyle.Regular), Brushes.Black, 70, 630);
6


Bitmap bm = new Bitmap(this.txt16.Width, this.txt16.Height);
txt16.DrawToBitmap(bm, new Rectangle(0, 0, this.txt16.Width,
this.txt16.Height));

e.Graphics.DrawImage(bm, 30, 670);
e.Graphics.DrawString(l_ngay.Text, new Font("Times New Roman",
14, FontStyle.Regular), Brushes.Black, 420, 950);
e.Graphics.DrawString(tngay.Text, new Font("Times New Roman",
14, FontStyle.Regular), Brushes.Black, 585, 950);
e.Graphics.DrawString(tthang.Text, new Font("Times New Roman",
14, FontStyle.Regular), Brushes.Black, 663, 950);
e.Graphics.DrawString(txtnam.Text, new Font("Times New Roman",
14, FontStyle.Regular), Brushes.Black, 730, 950);
e.Graphics.DrawString(L_TCA.Text, new Font("Times New
Roman", 14, FontStyle.Bold), Brushes.Black, 500, 980);
e.Graphics.DrawString(lmau.Text, new Font("Times New Roman",
9, FontStyle.Regular), Brushes.Black, 630, 40);
//==================
}
private void thuchienin()
{
xemin.Document = document;
if (xemin.ShowDialog() == DialogResult.OK)
{
document.Print();
}
}
// vô hiệu hóa nút X==========================
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;

myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
return myCp;
7


}
}

#region
private void btnthoat_Click_1(object sender, EventArgs e)
{
this.Close();
Form1 Chuyen_di = new Form1();
Chuyen_di.Show();
}
private void t12_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
t13.Focus();
}
}
private void t13_KeyPress_1(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
t14.Focus();
}
}
private void t14_KeyPress_1(object sender, KeyPressEventArgs e)

{
e.KeyChar = char.Parse(e.KeyChar.ToString().ToUpper());
if (e.KeyChar == 13)
{
t15.Focus();
}
}
private void t10_KeyPress_1(object sender, KeyPressEventArgs e)
8


{
if (e.KeyChar == 13)
{
btn_chuyen.Focus();
}
}
#endregion

private void txt16_KeyPress(object sender, KeyPressEventArgs e)
{
e.KeyChar = char.Parse(e.KeyChar.ToString().ToUpper());
}
//-------------------------------------------------------------------------------------------------private void btn_tim_Click_1(object sender, EventArgs e)
{
t12.Focus();
try
{
OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data

Source=cutru.mdb");
da = new OleDbDataAdapter("select * from tblcutru where sonha
= '" + txt_sn.Text.Trim() + "' AND ap= '" + cbb_ap.Text.Trim() + "'", con);
dt = new DataTable("tblcutru");
da.Fill(dt);
dw = new DataView(dt);
dtgtim_cd.DataSource = dw;
}
catch
{
MessageBox.Show("Không tìm được tên");
9


}
}
private void btn_in_Click_1(object sender, EventArgs e)
{
if (t12.TextLength == 0)
{ MessageBox.Show("Nơi chuyển đến đã bỏ trống, yêu cầu điền đầy
đủ thông tin mới in được"); }
else if (t13.TextLength == 0)
{ MessageBox.Show("Thông tin lý do chuyển đã bị trống, yêu cầu
điền vào"); }
else if (t14.TextLength == 0)
{ MessageBox.Show("Chưa điền họ tên chủ hộ"); }
else
try
{
thuchienin();

}
catch
{
}
}
private void dtgtim_cd_CellEnter_1(object sender,
DataGridViewCellEventArgs e)
{
try
{
txtso.Text = dtgtim_cd.CurrentRow.Cells[0].Value.ToString();
t11.Text = dtgtim_cd.CurrentRow.Cells[1].Value.ToString();
tap.Text = dtgtim_cd.CurrentRow.Cells[2].Value.ToString();
t1.Text = dtgtim_cd.CurrentRow.Cells[3].Value.ToString();
t15.Text = dtgtim_cd.CurrentRow.Cells[4].Value.ToString();
t4.Text = dtgtim_cd.CurrentRow.Cells[5].Value.ToString();
t2.Text = dtgtim_cd.CurrentRow.Cells[6].Value.ToString();
t5.Text = dtgtim_cd.CurrentRow.Cells[7].Value.ToString();
t6.Text = dtgtim_cd.CurrentRow.Cells[8].Value.ToString();
10


t7.Text = dtgtim_cd.CurrentRow.Cells[9].Value.ToString();
dtnamsinh.Text =
dtgtim_cd.CurrentRow.Cells[13].Value.ToString();

}
catch
{
}

}
private void btn_chuyen_Click_1(object sender, EventArgs e)
{
btn_in.Enabled = true;
if (txtso.TextLength == 0 || t6.TextLength == 0 || t12.TextLength ==
0 || t13.TextLength == 0 || t14.TextLength == 0)
{
MessageBox.Show("Thông tin số TT hoặc họ tên hoặc giới tính
còn trống, không chuyển được");
}
else
try
{
dtc.ketnoi();
dtc.command("INSERT INTO
tblchuyen(stt,sonha,ap,hoten,qhch,namsinh,gioitinh,noisinh,dantoc,tongiao,n
oicd,ngaycd)" +
"VALUES('" + txtso.Text + "','" + t11.Text + "','" + tap.Text + "','" +
t1.Text + "','" + t15.Text + "','" + dtnamsinh.Value.ToShortDateString() + "',
'" + t2.Text + "','" + t5.Text + "','" + t6.Text + "','" + t7.Text + "','" + t12.Text
+ "','" + ngaychuyen.Value.ToShortDateString() + "')");
MessageBox.Show("Đã chuyển thành công");
}

11


catch
{
MessageBox.Show("không chuyển được, vì số chuyển bị trùng,

thêm một ký tự bất kỳ vào số chuyển");
}
}
private void btnchuyen_Click_1(object sender, EventArgs e)
{
if (txtso.TextLength == 0)
{
MessageBox.Show("chưa có dữ liệu để xóa");
}
else
try
{
dtc.command("DELETE FROM tblcutru WHERE stt='" +
txtso.Text + "' ");
MessageBox.Show("Đã xóa");
}
catch
{
MessageBox.Show("Đã chuyển rồi, không chuyển được nữa");
}
}

}
}

12


13




×