按照进程此节应设计F_Manfile窗体,主要适用于与共信息的录入,以及员工信息的修改,查询,报表等功能。这一节首先设计所有tabControl里面的第一个界面,员工基本信息界面,首先,界面设计如下:
对于职工的基本信息的设置大体如下:
使用了GridView控件显示查询的结果,通过几个GroupBox控件将区分开;接下来开始此界面的代码设计:
首先,在C#中万物皆对象,所以我们先实例化几个对象,并定义当前窗体中所使用的公共变量:
DataClass.MyMeans MyDataClass = new DataClass.MyMeans();
ModuleClass.MyModule MyMC = new ModuleClass.MyModule();
public static DataSet MyDS_Grid;
public static string tem_Field = "";
public static string tem_Value = "";
public static string tem_ID = "";
public static int hold_n = 0;
public static byte[] imgBytesIn; //用来存储图片的二进制数
public static int Ima_n = 0; //判断是否对图片进行了操作
public static string Part_ID = ""; //存储数据表的ID信息
对于窗体在生成时,我们可以设计其load事件完成初始化的工作:
private void F_ManFile_Load(object sender, EventArgs e)
{
//用dataGridView1控件显示职工的名称
MyDS_Grid = MyDataClass.GetDataSet(DataClass.MyMeans.AllSql, "tb_Stuffbusic");
dataGridView1.DataSource = MyDS_Grid.Tables[0];
dataGridView1.AutoGenerateColumns = true; //是否自动创建列
dataGridView1.Columns[0].Width = 60;
dataGridView1.Columns[1].Width = 80;
for (int i = 2; i < dataGridView1.ColumnCount; i++) //隐藏dataGridView1控件中不需要的列字段
{
dataGridView1.Columns[i].Visible = false;
}
MyMC.MaskTextBox_Format(S_3); //指定MaskedTextBox控件的格式
MyMC.MaskTextBox_Format(S_10);
MyMC.MaskTextBox_Format(S_21);
MyMC.MaskTextBox_Format(S_27);
MyMC.MaskTextBox_Format(S_28);
MyMC.CoPassData(S_2, "tb_Folk"); //向“民族类别”列表框中添加信息
MyMC.CoPassData(S_5, "tb_Kultur"); //向"文化程度”列表框中添加信息
MyMC.CoPassData(S_8, "tb_Visage"); //向"正治面貌”列表框中添加信息
MyMC.CoPassData(S_12, "tb_EmployeeGenre"); //向"职工类别”列表框中添加信息
MyMC.CoPassData(S_13, "tb_Business"); //向"职务类别”列表框中添加信息
MyMC.CoPassData(S_14, "tb_Laborage"); //向"工资类别”列表框中添加信息
MyMC.CoPassData(S_15, "tb_Branch"); //向"部门类别”列表框中添加信息
MyMC.CoPassData(S_16, "tb_Duthcall"); //向"职称类别”列表框中添加信息
MyMC.CityInfo(S_23, "select distinct beaware from tb_City", 0);
S_23.AutoCompleteMode = AutoCompleteMode.SuggestAppend; //使S_BeAware控件具有查询功能
S_23.AutoCompleteSource = AutoCompleteSource.ListItems;
textBox1.Text = Grid_Inof(dataGridView1); //显示职工信息表的首记录
DataClass.MyMeans.AllSql = "Select * from tb_Stuffbusic";
}
其中,对于CoPassData方法,MaskTextBox方法,以及下面的Date_Format方法等在前面的文章中提到过,是在MyModule类中进行了实现。
然而,在上述代码中倒数第三行中的Grod_Iinfo方法的设计如下:
public string Grid_Inof(DataGridView DGrid)
{
byte[] pic; //定义一个字节数组
//当DataGridView控件的记录>1时,将当前行中信息显示在相应的控件上
if (DGrid.RowCount > 1)
{
//向空间中指定位置添加职员的信息
S_0.Text = DGrid[0, DGrid.CurrentCell.RowIndex].Value.ToString();
S_1.Text = DGrid[1, DGrid.CurrentCell.RowIndex].Value.ToString();
S_2.Text = Convert.ToString(DGrid[2, DGrid.CurrentCell.RowIndex].Value).Trim();
S_3.Text = MyMC.Date_Format(Convert.ToString(DGrid[3, DGrid.CurrentCell.RowIndex].Value).Trim());
S_4.Text = Convert.ToString(DGrid[4, DGrid.CurrentCell.RowIndex].Value).Trim();
S_5.Text = DGrid[5, DGrid.CurrentCell.RowIndex].Value.ToString();
S_6.Text = DGrid[6, DGrid.CurrentCell.RowIndex].Value.ToString();
S_7.Text = DGrid[7, DGrid.CurrentCell.RowIndex].Value.ToString();
S_8.Text = DGrid[8, DGrid.CurrentCell.RowIndex].Value.ToString();
S_9.Text = DGrid[9, DGrid.CurrentCell.RowIndex].Value.ToString();
S_10.Text = MyMC.Date_Format(Convert.ToString(DGrid[10, DGrid.CurrentCell.RowIndex].Value).Trim());
S_11.Text = Convert.ToString(DGrid[11, DGrid.CurrentCell.RowIndex].Value).Trim();
S_12.Text = DGrid[12, DGrid.CurrentCell.RowIndex].Value.ToString();
S_13.Text = DGrid[13, DGrid.CurrentCell.RowIndex].Value.ToString();
S_14.Text = DGrid[14, DGrid.CurrentCell.RowIndex].Value.ToString();
S_15.Text = DGrid[15, DGrid.CurrentCell.RowIndex].Value.ToString();
S_16.Text = DGrid[16, DGrid.CurrentCell.RowIndex].Value.ToString();
S_17.Text = DGrid[17, DGrid.CurrentCell.RowIndex].Value.ToString();
S_18.Text = DGrid[18, DGrid.CurrentCell.RowIndex].Value.ToString();
S_19.Text = DGrid[19, DGrid.CurrentCell.RowIndex].Value.ToString();
S_20.Text = DGrid[20, DGrid.CurrentCell.RowIndex].Value.ToString();
S_21.Text = MyMC.Date_Format(Convert.ToString(DGrid[21, DGrid.CurrentCell.RowIndex].Value).Trim());
S_22.Text = DGrid[22, DGrid.CurrentCell.RowIndex].Value.ToString();
S_23.Text = DGrid[24, DGrid.CurrentCell.RowIndex].Value.ToString();
S_24.Text = DGrid[25, DGrid.CurrentCell.RowIndex].Value.ToString();
S_25.Text = Convert.ToString(DGrid[26, DGrid.CurrentCell.RowIndex].Value).Trim();
S_26.Text = DGrid[27, DGrid.CurrentCell.RowIndex].Value.ToString();
S_27.Text = MyMC.Date_Format(Convert.ToString(DGrid[28, DGrid.CurrentCell.RowIndex].Value).Trim());
S_28.Text = MyMC.Date_Format(Convert.ToString(DGrid[29, DGrid.CurrentCell.RowIndex].Value).Trim());
S_29.Text = Convert.ToString(DGrid[30, DGrid.CurrentCell.RowIndex].Value).Trim();
try
{
//将数据库中的图片存入到字节数组中
pic = (byte[])(MyDS_Grid.Tables[0].Rows[DGrid.CurrentCell.RowIndex][23]);
MemoryStream ms = new MemoryStream(pic); //将字节数组存入到二进制流中
S_Photo.Image = Image.FromStream(ms); //二进制流Image控件中显示
}
catch { S_Photo.Image = null; } //当出现错误时,将Image控件清空
tem_ID = S_0.Text.Trim(); //获取当前职伯编号
return DGrid[1, DGrid.CurrentCell.RowIndex].Value.ToString(); //返回当前职工的姓名
}
else
{
//使用MyMeans公共类中的Clear_Control()方法清空指定控件集中的相应控件
MyMC.Clear_Control(tabControl1.TabPages[0].Controls);
tem_ID = "";
return "";
}
}
在这个方法中,需要将照片转换为二进制流进行储存,因为使用的是关系型数据库的限制,使用数据流存储将会更加方便一些:
具体的方法如下,将照片转换为字节数组:
public void Read_Image(OpenFileDialog openF, PictureBox MyImage) //
{
openF.Filter = "*.jpg|*.jpg|*.bmp|*.bmp"; //指定OpenFileDialog控件打开的文件格式
if (openF.ShowDialog(this) == DialogResult.OK) //如果打开了图片文件
{
try
{
MyImage.Image = System.Drawing.Image.FromFile(openF.FileName); //将图片文件存入到PictureBox控件中
string strimg = openF.FileName.ToString(); //记录图片的所在路径
FileStream fs = new FileStream(strimg, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
}
catch
{
MessageBox.Show("您选择的图片不能被读取或文件类型不对!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
S_Photo.Image = null;
}
}
}
当点击选择图片时将调用此事件:
private void button7_Click(object sender, EventArgs e)
{
Read_Image(openFileDialog1, S_Photo);
Ima_n = 1;
}
当点击图片显示框下面的清除时,将使用此事件实现对照片的清除工作:
private void button8_Click(object sender, EventArgs e)
{
S_Photo.Image = null;
imgBytesIn = new byte[65536];
Ima_n = 2;
}
分类查询和浏览按钮的实现如下,在这之前有很多的关于查询的方法,在这里就不再赘述了:
分类查询中的查询条件的实现,并从数据库中的表中添加选择项:
private void comboBox1_TextChanged(object sender, EventArgs e)
{
switch (comboBox1.SelectedIndex) //向comboBox2控件中添加相应的查询条件
{
case 0:
{
MyMC.CityInfo(comboBox2, "select distinct StuffName from tb_Stuffbusic", 0); //职工姓名
tem_Field = "StuffName";
break;
}
case 1: //性别
{
comboBox2.Items.Clear();
comboBox2.Items.Add("男");
comboBox2.Items.Add("女");
tem_Field = "Sex";
break;
}
case 2:
{
MyMC.CoPassData(comboBox2, "tb_Folk"); //民族类别
tem_Field = "Folk";
break;
}
case 3:
{
MyMC.CoPassData(comboBox2, "tb_Kultur"); //文化程度
tem_Field = "Kultur";
break;
}
case 4:
{
MyMC.CoPassData(comboBox2, "tb_Visage"); //正治面貌
tem_Field = "Visage";
break;
}
case 5:
{
MyMC.CoPassData(comboBox2, "tb_EmployeeGenre"); //职工类别
tem_Field = "Employee";
break;
}
case 6:
{
MyMC.CoPassData(comboBox2, "tb_Business"); //职务类别
tem_Field = "Business";
break;
}
case 7:
{
MyMC.CoPassData(comboBox2, "tb_Branch"); //部门类别
tem_Field = "Branch";
break;
}
case 8:
{
MyMC.CoPassData(comboBox2, "tb_Duthcall"); //职称类别
tem_Field = "Duthcall";
break;
}
case 9:
{
MyMC.CoPassData(comboBox2, "tb_Laborage"); //工资类别
tem_Field = "Laborage";
break;
}
}
}
查询条件的设计:
private void comboBox2_TextChanged(object sender, EventArgs e)
{
try
{
tem_Value = comboBox2.SelectedItem.ToString();
Condition_Lookup(tem_Value);
}
catch
{
comboBox2.Text = "";
MessageBox.Show("只能以选择方式查询。");
}
}
同时,上述的事件中有对Condition_Lookup方法的调用,这个方法实现查询条件的设置,方法设计如下:
public void Condition_Lookup(string C_Value)
{
MyDS_Grid = MyDataClass.GetDataSet("Select * from tb_Stuffbusic where " + tem_Field + "='" + tem_Value + "'", "tb_Stuffbusic");
dataGridView1.DataSource = MyDS_Grid.Tables[0];
textBox1.Text = Grid_Inof(dataGridView1); //显示职工信息表的当前记录
}
四个浏览按钮的设计如下:
private void N_First_Click(object sender, EventArgs e)(由左到右,按钮1)
{
try
{
int ColInd = 0;
if (dataGridView1.CurrentCell.ColumnIndex == -1 || dataGridView1.CurrentCell.ColumnIndex > 1)
ColInd = 0;
else
ColInd = dataGridView1.CurrentCell.ColumnIndex;
if ((((Button)sender).Name) == "N_First")
{
dataGridView1.CurrentCell = this.dataGridView1[ColInd, 0];
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 0, 0, 1, 1);
}
if ((((Button)sender).Name) == "N_Previous")
{
if (dataGridView1.CurrentCell.RowIndex == 0)
{
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 0, 0, 1, 1);
}
else
{
dataGridView1.CurrentCell = this.dataGridView1[ColInd, dataGridView1.CurrentCell.RowIndex - 1];
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 1, 1, 1, 1);
}
}
if ((((Button)sender).Name) == "N_Next")
{
if (dataGridView1.CurrentCell.RowIndex == dataGridView1.RowCount - 2)
{
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 1, 1, 0, 0);
}
else
{
dataGridView1.CurrentCell = this.dataGridView1[ColInd, dataGridView1.CurrentCell.RowIndex + 1];
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 1, 1, 1, 1);
}
}
if ((((Button)sender).Name) == "N_Cauda")
{
dataGridView1.CurrentCell = this.dataGridView1[ColInd, dataGridView1.RowCount - 2];
MyMC.Ena_Button(N_First, N_Previous, N_Next, N_Cauda, 1, 1, 0, 0);
}
}
catch { }
}
private void N_Previous_Click(object sender, EventArgs e)(按钮2)
{
N_First_Click(sender, e);
}
private void N_Cauda_Click(object sender, EventArgs e)(按钮3)
{
N_First_Click(sender, e);
}
private void N_Next_Click(object sender, EventArgs e)(按钮4)
{
N_First_Click(sender, e);
}
当点击Word时,可以输出Word文档,本次设计的是以office2003的类库以及相应的组件进行编写,其相应的事件设计如下:
public void but_Table_Click(object sender, EventArgs e)
{
object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
//创建Word文档
Word.Application wordApp = new Word.ApplicationClass();
Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = true;
//设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2"));
Object strat = Type.Missing;
object end = Type.Missing;
PictureBox pp = new PictureBox();
int p1 = 0;
for (int i = 0; i < MyDS_Grid.Tables[0].Rows.Count; i++)
{
try
{
byte[] pic = (byte[])(MyDS_Grid.Tables[0].Rows[i][23]);
MemoryStream ms = new MemoryStream();
pp.Image = Image.FromStream(ms);
pp.Image.Save(@"C:\22.bmp");
}
catch
{
p1 = 1;
}
object rng = Type.Missing;
string strInfo = "职工基本信息表" + "(" + MyDS_Grid.Tables[0].Rows[i][1].ToString() + ")";
strat = 0;
end = 0;
wordDoc.Range(ref strat, ref end).InsertBefore(strInfo);
wordDoc.Range(ref strat, ref end).Font.Name = "Verdana";
wordDoc.Range(ref strat, ref end).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
strat = strInfo.Length;
end = strInfo.Length;
wordDoc.Range(ref strat, ref end).InsertParagraphAfter();
object missingValue = Type.Missing;
object location = strInfo.Length;
Word.Range rng2 = wordDoc.Range(ref location, ref location);
wordDoc.Tables.Add(rng2, 14, 6, ref missingValue, ref missingValue);
wordDoc.Tables[1].Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;
wordDoc.Tables[1].Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));
wordDoc.Tables[1].Range.Font.Size = 10;
wordDoc.Tables[1].Range.Font.Name = "宋体";
//设置表格样式
wordDoc.Tables[1].Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
wordDoc.Tables[1].Borders.InsideLineWidth = Word.WdLineWidth.wdLineWidth050pt;
wordDoc.Tables[1].Borders.InsideColor = Word.WdColor.wdColorAutomatic;
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;//设置右对齐
//第5行显示
wordDoc.Tables[1].Cell(1, 5).Merge(wordDoc.Tables[1].Cell(5, 6));
//第6行显示
wordDoc.Tables[1].Cell(6, 5).Merge(wordDoc.Tables[1].Cell(6, 6));
//第9行显示
wordDoc.Tables[1].Cell(9, 4).Merge(wordDoc.Tables[1].Cell(9, 6));
//第12行显示
wordDoc.Tables[1].Cell(12, 2).Merge(wordDoc.Tables[1].Cell(12, 6));
//第13行显示
wordDoc.Tables[1].Cell(13, 2).Merge(wordDoc.Tables[1].Cell(13, 6));
//第14行显示
wordDoc.Tables[1].Cell(14, 2).Merge(wordDoc.Tables[1].Cell(14, 6));
//第1行赋值
wordDoc.Tables[1].Cell(1, 1).Range.Text = "职工编号:";
wordDoc.Tables[1].Cell(1, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][0].ToString();
wordDoc.Tables[1].Cell(1, 3).Range.Text = "职工姓名:";
wordDoc.Tables[1].Cell(1, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][1].ToString();
//第1行赋值
wordDoc.Tables[1].Cell(1, 1).Range.Text = "职工编号:";
wordDoc.Tables[1].Cell(1, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][0].ToString();
wordDoc.Tables[1].Cell(1, 3).Range.Text = "职工姓名:";
wordDoc.Tables[1].Cell(1, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][1].ToString();
//插入图片
if (p1 == 0)
{
string FileName = @"C:\22.bmp";//图片所在路径
object LinkToFile = false;
object SaveWithDocument = true;
object Anchor = wordDoc.Tables[1].Cell(1, 5).Range; //指定图片插入的区域
//将图片插入到单元格中
wordDoc.Tables[1].Cell(1, 5).Range.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);
}
p1 = 0;
//第2行赋值
wordDoc.Tables[1].Cell(2, 1).Range.Text = "民族类别:";
wordDoc.Tables[1].Cell(2, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][2].ToString();
wordDoc.Tables[1].Cell(2, 3).Range.Text = "出生日期:";
try
{
wordDoc.Tables[1].Cell(2, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][3]).ToShortDateString());
}
catch { wordDoc.Tables[1].Cell(2, 4).Range.Text = ""; }
//Convert.ToString(MyDS_Grid.Tables[0].Rows[i][3]);
//第3行赋值
wordDoc.Tables[1].Cell(3, 1).Range.Text = "年龄:";
wordDoc.Tables[1].Cell(3, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][4]);
wordDoc.Tables[1].Cell(3, 3).Range.Text = "文化程序:";
wordDoc.Tables[1].Cell(3, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][5].ToString();
//第4行赋值
wordDoc.Tables[1].Cell(4, 1).Range.Text = "婚姻:";
wordDoc.Tables[1].Cell(4, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][6].ToString();
wordDoc.Tables[1].Cell(4, 3).Range.Text = "性别:";
wordDoc.Tables[1].Cell(4, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][7].ToString();
//第5行赋值
wordDoc.Tables[1].Cell(5, 1).Range.Text = "政治面貌:";
wordDoc.Tables[1].Cell(5, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][8].ToString();
wordDoc.Tables[1].Cell(5, 3).Range.Text = "单位工作时间:";
try
{
wordDoc.Tables[1].Cell(5, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[0][10]).ToShortDateString());
}
catch { wordDoc.Tables[1].Cell(5, 4).Range.Text = ""; }
//第6行赋值
wordDoc.Tables[1].Cell(6, 1).Range.Text = "籍贯:";
wordDoc.Tables[1].Cell(6, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][24].ToString();
wordDoc.Tables[1].Cell(6, 3).Range.Text = MyDS_Grid.Tables[0].Rows[i][25].ToString();
wordDoc.Tables[1].Cell(6, 4).Range.Text = "身份证:";
wordDoc.Tables[1].Cell(6, 5).Range.Text = MyDS_Grid.Tables[0].Rows[i][9].ToString();
//第7行赋值
wordDoc.Tables[1].Cell(7, 1).Range.Text = "工龄:";
wordDoc.Tables[1].Cell(7, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][11]);
wordDoc.Tables[1].Cell(7, 3).Range.Text = "职工类别:";
wordDoc.Tables[1].Cell(7, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][12].ToString();
wordDoc.Tables[1].Cell(7, 5).Range.Text = "职务类别:";
wordDoc.Tables[1].Cell(7, 6).Range.Text = MyDS_Grid.Tables[0].Rows[i][13].ToString();
//第8行赋值
wordDoc.Tables[1].Cell(8, 1).Range.Text = "工资类别:";
wordDoc.Tables[1].Cell(8, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][14].ToString();
wordDoc.Tables[1].Cell(8, 3).Range.Text = "部门类别:";
wordDoc.Tables[1].Cell(8, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][15].ToString();
wordDoc.Tables[1].Cell(8, 5).Range.Text = "职称类别:";
wordDoc.Tables[1].Cell(8, 6).Range.Text = MyDS_Grid.Tables[0].Rows[i][16].ToString();
//第9行赋值
wordDoc.Tables[1].Cell(9, 1).Range.Text = "月工资:";
wordDoc.Tables[1].Cell(9, 2).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][26]);
wordDoc.Tables[1].Cell(9, 3).Range.Text = "银行帐号:";
wordDoc.Tables[1].Cell(9, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][27].ToString();
//第10行赋值
wordDoc.Tables[1].Cell(10, 1).Range.Text = "合同起始日期:";
try
{
wordDoc.Tables[1].Cell(10, 2).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][28]).ToShortDateString());
}
catch { wordDoc.Tables[1].Cell(10, 2).Range.Text = ""; }
//Convert.ToString(MyDS_Grid.Tables[0].Rows[i][28]);
wordDoc.Tables[1].Cell(10, 3).Range.Text = "合同结束日期:";
try
{
wordDoc.Tables[1].Cell(10, 4).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][29]).ToShortDateString());
}
catch { wordDoc.Tables[1].Cell(10, 4).Range.Text = ""; }
//Convert.ToString(MyDS_Grid.Tables[0].Rows[i][29]);
wordDoc.Tables[1].Cell(10, 5).Range.Text = "合同年限:";
wordDoc.Tables[1].Cell(10, 6).Range.Text = Convert.ToString(MyDS_Grid.Tables[0].Rows[i][30]);
//第11行赋值
wordDoc.Tables[1].Cell(11, 1).Range.Text = "电话:";
wordDoc.Tables[1].Cell(11, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][17].ToString();
wordDoc.Tables[1].Cell(11, 3).Range.Text = "手机:";
wordDoc.Tables[1].Cell(11, 4).Range.Text = MyDS_Grid.Tables[0].Rows[i][18].ToString();
wordDoc.Tables[1].Cell(11, 5).Range.Text = "毕业时间:";
try
{
wordDoc.Tables[1].Cell(11, 6).Range.Text = Convert.ToString(Convert.ToDateTime(MyDS_Grid.Tables[0].Rows[i][21]).ToShortDateString());
}
catch { wordDoc.Tables[1].Cell(11, 6).Range.Text = ""; }
//Convert.ToString(MyDS_Grid.Tables[0].Rows[i][21]);
//第12行赋值
wordDoc.Tables[1].Cell(12, 1).Range.Text = "毕业学校:";
wordDoc.Tables[1].Cell(12, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][19].ToString();
//第13行赋值
wordDoc.Tables[1].Cell(13, 1).Range.Text = "主修专业:";
wordDoc.Tables[1].Cell(13, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][20].ToString();
//第14行赋值
wordDoc.Tables[1].Cell(14, 1).Range.Text = "家庭地址:";
wordDoc.Tables[1].Cell(14, 2).Range.Text = MyDS_Grid.Tables[0].Rows[i][22].ToString();
wordDoc.Range(ref strat, ref end).InsertParagraphAfter();//插入回车
wordDoc.Range(ref strat, ref end).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; //设置字体局中
}
}
当点击添加按钮时,其响应事件设计如下:
private void Sut_Add_Click(object sender, EventArgs e)
{
MyMC.Clear_Control(tabControl1.TabPages[0].Controls); //清空职工基本信息的相应文本框
S_0.Text = MyMC.GetAutoCoding("tb_Stuffbusic", "ID"); //自动添加编号
hold_n = 1; //用于记录添加操作的标识
MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 0, 0, 1, 1);
groupBox5.Text = "当前正在添加信息";
Img_Clear.Enabled = true; //使图片选择按钮为可用状态
Img_Save.Enabled = true;
}
当点击修改按钮时,其事件的相应程序如下:
private void Sut_Amend_Click(object sender, EventArgs e)
{
hold_n = 2; //用于记录修改操作的标识
MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 0, 0, 1, 1);
groupBox5.Text = "当前正在修改信息";
Img_Clear.Enabled = true; //使图片选择按钮为可用状态
Img_Save.Enabled = true;
}
当点击删除时,其事件的相应程序如下:
private void Sut_Delete_Click(object sender, EventArgs e)
{
if (dataGridView1.RowCount < 2) //判断dataGridView1控件中是否有记录
{
MessageBox.Show("数据表为空,不可以删除。");
return;
}
//删除职工信息表中的当前记录,及其他相关表中的信息
MyDataClass.GetA_M_D_command("Delete tb_Stuffbusic where ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_WordResume where Sut_ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_Family where Sut_ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_TrainNote where Sut_ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_RANDP where Sut_ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_WordResume where Sut_ID='" + S_0.Text.Trim() + "'");
MyDataClass.GetA_M_D_command("Delete tb_Individual where ID='" + S_0.Text.Trim() + "'");
Sut_Cancel_Click(sender, e); //调用“取消”按钮的单击事件
}
当点击取消按钮时,事件的响应代码如下:
private void Sut_Cancel_Click(object sender, EventArgs e)
{
hold_n = 0; //恢复原始标识
MyMC.Ena_Button(Sut_Add, Sut_Amend, Sut_Cancel, Sut_Save, 1, 1, 0, 0);
groupBox5.Text = "";
Ima_n = 0;
if (tem_Field == "")
button1_Click(sender, e);
else
Condition_Lookup(tem_Value);
Img_Clear.Enabled = false;
Img_Save.Enabled = false;
}
当点击保存按钮时,事件的相应程序设计如下:
private void Sut_Save_Click(object sender, EventArgs e)
{
if (tabControl1.SelectedTab.Name == "tabPage6") //如果当前是“个人简历”选项卡
{
//通过MyMeans公共类中的getcom()方法查询当前职工是否添加了个人简历
SqlDataReader Read_Memo = MyDataClass.getCommand("Select * from tb_Individual where ID='" + tem_ID + "'");
if (Read_Memo.Read()) //如果有记录
//将当前设置的个人简历进行修改
MyDataClass.GetA_M_D_command("update tb_Individual set Memo='" + Ind_Mome.Text + "' where ID='" + tem_ID + "'");
else
//如果没有记录,则进行添加操作
MyDataClass.GetA_M_D_command("insert into tb_Individual (ID,Memo) values('" + tem_ID + "','" + Ind_Mome.Text + "')");
}
else //如果当前是“职工基本信息”选项卡
{
//定义字符串变量,并存储将“职工基本信息表”中的所有字段
string All_Field = "ID,StuffName,Folk,Birthday,Age,Kultur,Marriage,Sex,Visage,IDCard,Workdate,WorkLength,Employee,Business,Laborage,Branch ,Duthcall,Phone,Handset,School,Speciality,GraduateDate,Address,BeAware,City,M_Pay,Bank,Pact_B,Pact_E,Pact_Y";
if (hold_n == 1 || hold_n == 2) //判断当前是添加,还是修改操作
{
ModuleClass.MyModule.ADDs = ""; //清空MyModule公共类中的ADDs变量
//用MyModule公共类中的Part_SaveClass()方法组合添加或修改的SQL语句
MyMC.Part_SaveClass(All_Field, S_0.Text.Trim(), "", tabControl1.TabPages[0].Controls, "S_", "tb_Stuffbusic", 30, hold_n);
//如果ADDs变量不为空,则通过MyMeans公共类中的getsqlcom()方法执行添加、修改操作
if (ModuleClass.MyModule.ADDs != "")
MyDataClass.GetA_M_D_command(ModuleClass.MyModule.ADDs);
}
if (Ima_n > 0) //如果图片标识大于0
{
//通过MyModule公共类中r的SaveImage()方法将图片存入数据库中
MyMC.SaveImage(S_0.Text.Trim(), imgBytesIn);
}
Sut_Cancel_Click(sender, e); //调用“取消”按钮的单击事件
}
}
到此,第一个页面,职工基本信息以及设计完毕,下节设计职工简历界面。