值班记录本

前言

值班记录本的功能很简单,只是textBox输入文本信息,然后插入到数据库中。

界面

值班记录界面
值班记录本

用到的控件

  • textBox
  • GroupBox
  • TabPage
  • Button等

实现

  • 程序启动
///<summary>
///值班本程序启动时,默认显示出各个控件的信息
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
private void zb_zbb_Load(object sender, EventArgs e)
{
    date = DateTime.Now.ToString("yyyyMMdd");//插入记录日期,转换格式存入数据库
    zbrxm.Text = user_login.M_name;
    this.fwq.Text = "正常";
    this.cc.Text = "正常";
    this.jhj.Text = "正常";
    this.ups.Text = "正常";
    this.sphy.Text = "正常";
    this.rizhi.Text = "一切正常";
    this.beitejia.Text = "正常";
    this.auto.Text = "正常";
    this.tpdev.Text = "";
    this.tplog.Text = "";
    this.diskc.Text = "";
    this.diskd.Text = "";
    this.diski.Text = "";
    this.richTextBox1.Text = "正常";
    this.richTextBox2.Text = "正常";
    this.richTextBox3.Text = "正常";
    this.textBox1.Text = "正常";
    this.textBox2.Text = "正常";
    this.textBox3.Text = "正常";
    this.textBox4.Text = "正常";
    this.textBox5.Text = "正常";
    this.textBox6.Text = "正常";
    this.textBox7.Text = "正常";
    this.textBox8.Text = "";
    this.textBox9.Text = "";
    nowtime_label.Text = System.DateTime.Now.ToString();
    label8.Text = "G";
}
  • 点击保存按钮
/// <summary>
/// 按钮提交所有数据至数据库-
/// 值班日期code的string没写
/// </summary>
private void baocun_Click(object sender, EventArgs e)
{
    try{
        string check = "select Count(1) from zb_zbb where zbrqcode='" + date + "'";
        SqlConnection con = new SqlConnection(zb_class.zb_ConStr);
        con.Open();
        SqlCommand cmd = new SqlCommand(check, con);
        int count = Convert.ToInt32(zb_class.Get(check,"第一列数据",""));
    if (count>=1)
    {
        MessageBox.Show("今日值班日记已写过啦!");
        con.Close();//避免重复写值班记录
    }
    else 
    {
        if(textBox8.Text==""&&textBox9.Text=="")
    {
        MessageBox.Show("请检查温度或者湿度是否填写!");//因为温度和湿度的位置很容易被忽略,所以做个小提示
    }
    else
    {
        string time = DateTime.Now.ToString();
        string save =
        "insert into zb_zbb(zbrqcode,xm,zbrq,fuwuqi,cunchu,jiaohuanji,ups,shipinhuiyi,caozuoxitongshizhi,beitejia,autobackup,tempdev,templog,cpan,dpan,ipan,jifanghuanjing,wangluohuanjing,netapphuanjing,zhigongyibao,nonghe,yiyuanzhuye,xinyitushuguan,bijibendiannao,ruodianjingyaoshi,weixiugongju,wendu,shidu) VALUES ('" + date + "','" + user_login.M_name + "','" + nowtime_label.Text + "','" + fwq.Text.Trim() + "','" + cc.Text.Trim() + "','" + jhj.Text.Trim() + "','" + ups.Text.Trim() + "','" + sphy.Text.Trim() + "','" + rizhi.Text.Trim() + "','" + beitejia.Text.Trim() + "','" + auto.Text.Trim() + "','" + tpdev.Text.Trim() + label8.Text.Trim() + "','" + tplog.Text.Trim() + label8.Text.Trim() + "','" + diskc.Text.Trim() + label8.Text.Trim() + "','" + diskd.Text.Trim() + label8.Text.Trim() + "','" + diski.Text.Trim() + label8.Text.Trim() + "','" + richTextBox1.Text.Trim() + "','" + richTextBox2.Text.Trim() + "','" + richTextBox3.Text.Trim() + "','" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "','" + textBox4.Text.Trim() + "','" + textBox7.Text.Trim() + "','" + textBox6.Text.Trim() + "','" + textBox5.Text.Trim() + "','" + textBox8.Text.Trim() + wendu.ToString() + "','" + textBox9.Text.Trim() + shidu.ToString() + "')";//插入填写的内容

        zb_class.sqlzb_cmd(save);//调用zb_class里的sqlzb_cmd方法执行sql语句保存数据
    }
    }
    }
    catch{
        MessageBox.Show("有错误!");
    }


}

小结

这个功能比较简单,没什么要点,唯一要注意的就是日期的格式化,要注意与数据库的对应字段的字符格式相同。

posted @ 2016-04-25 11:45  lovedanr  阅读(690)  评论(0编辑  收藏  举报