⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkform.cs

📁 c# 人事工资管理系统平台,很好用嘎..你们看看参考
💻 CS
字号:
//文件名:CheckForm.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;
//using Microsoft.Office.Interop.Excel;
using System.Reflection;
//using Microsoft.Office.Core;

namespace MyPersonnel
{
    public partial class CheckForm : Form
    {
        public CheckForm()
        {
            InitializeComponent();
        }
        public string MyCompany;
        private void 考勤记录BindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.考勤记录BindingSource.EndEdit();
            this.考勤记录TableAdapter.Update(this.myPersonnelDataSet.考勤记录);
        }
        private void CheckForm_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“myPersonnelDataSet.考勤记录”中。您可以根据需要移动或移除它。
            this.考勤记录TableAdapter.Fill(this.myPersonnelDataSet.考勤记录);
            this.myPersonnelDataSet.考勤记录.Rows.Clear();
            for (int i = 2006; i < 2100; i++)
            {
                this.考勤年份ToolStripComboBox.Items.Add(i.ToString());
            }
            for (int i = 1; i < 13; i++)
            {
                this.月份ToolStripComboBox.Items.Add(i.ToString());
            }
            //获取公司的部门信息            
            String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            System.Data.DataTable MyDepartmentTable = new System.Data.DataTable();
            string MySQL = "Select 部门名称 From 公司部门";
            SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
            MyAdapter.Fill(MyDepartmentTable);
            foreach(DataRow MyRow in MyDepartmentTable.Rows)
            {
                this.部门ToolStripComboBox.Items.Add(MyRow[0].ToString());
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
        }

        private void 查询ToolStripButton_Click(object sender, EventArgs e)
        {
            if (this.考勤年份ToolStripComboBox.Text.Length < 1 || this.月份ToolStripComboBox.Text.Length < 1 || this.部门ToolStripComboBox.Text.Length < 1)
            {
                return;
            }
            try
            {
                this.考勤记录TableAdapter.FillBy(this.myPersonnelDataSet.考勤记录, Convert.ToInt16(this.考勤年份ToolStripComboBox.Text),Convert.ToInt16(this.月份ToolStripComboBox.Text), this.部门ToolStripComboBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            if (this.myPersonnelDataSet.考勤记录.Rows.Count < 1)
            {                          
                String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
                SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
                MyConnection.Open();
                System.Data.DataTable MyQueryTable = new System.Data.DataTable();
                string MySQL = "Select * From 在职员工视图 WHERE 部门='" + this.部门ToolStripComboBox.Text + "'";
                SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
                MyAdapter.Fill(MyQueryTable);
                foreach (DataRow MyRow in MyQueryTable.Rows)
                {
                    string My自编号=this.GetMyID();
                    string My员工编号=MyRow[1].ToString();
                    string My员工姓名=MyRow[3].ToString();
                    int My考勤年份 = Convert.ToInt16(this.考勤年份ToolStripComboBox.Text);
                    int My考勤月份 = Convert.ToInt16(this.月份ToolStripComboBox.Text);
                    MySQL = "INSERT INTO 考勤记录([自编号] ,[员工编号], [员工姓名], [考勤年份], [考勤月份]) VALUES (@自编号 ,@员工编号, @员工姓名, @考勤年份, @考勤月份)";
                    MyConnection = new SqlConnection(MySQLConnectionString);
                    MyConnection.Open();
                    SqlCommand MyCommand = MyConnection.CreateCommand();
                    MyCommand.CommandText = MySQL;
                    MyCommand.Parameters.Add(new SqlParameter("@自编号", SqlDbType.VarChar));
                    MyCommand.Parameters.Add(new SqlParameter("@员工编号", SqlDbType.VarChar));
                    MyCommand.Parameters.Add(new SqlParameter("@员工姓名", SqlDbType.VarChar));
                    MyCommand.Parameters.Add(new SqlParameter("@考勤年份", SqlDbType.Int));
                    MyCommand.Parameters.Add(new SqlParameter("@考勤月份", SqlDbType.Int));

                    MyCommand.Parameters["@自编号"].Value = My自编号;
                    MyCommand.Parameters["@员工编号"].Value = My员工编号;
                    MyCommand.Parameters["@员工姓名"].Value = My员工姓名;
                    MyCommand.Parameters["@考勤年份"].Value = My考勤年份;
                    MyCommand.Parameters["@考勤月份"].Value = My考勤月份;
                    MyCommand.ExecuteNonQuery();
                }
                if (MyConnection.State == ConnectionState.Open)
                {
                    MyConnection.Close();
                }
                查询ToolStripButton_Click(null, null);
            }
        }
        private string GetMyID()
        {
            //自动计算考勤自编号
            String MySQLConnectionString = global::MyPersonnel.Properties.Settings.Default.MyPersonnelConnectionString;
            SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
            MyConnection.Open();
            SqlCommand MyCommand = MyConnection.CreateCommand();
            MyCommand.CommandText = "Select max(自编号) 最大编号 From 考勤记录";
            object MyResult = MyCommand.ExecuteScalar();
            Int64 MyID = 1;
            if (MyResult != System.DBNull.Value)
            {
                String MyMaxID = MyResult.ToString().Trim();
                MyMaxID = MyMaxID.Substring(2, MyMaxID.Length - 2);
                MyID = Convert.ToInt64(MyMaxID) + 1;
            }
            int MyLength = MyID.ToString().Length;
            string MyNewID = "";
            switch (MyLength)
            {
                case 1:
                    MyNewID = "KQ0000000" + MyID.ToString();
                    break;
                case 2:
                    MyNewID = "KQ000000" + MyID.ToString();
                    break;
                case 3:
                    MyNewID = "KQ00000" + MyID.ToString();
                    break;
                case 4:
                    MyNewID = "KQ0000" + MyID.ToString();
                    break;
                case 5:
                    MyNewID = "KQ000" + MyID.ToString();
                    break;
                case 6:
                    MyNewID = "KQ00" + MyID.ToString();
                    break;
                case 7:
                    MyNewID = "KQ0" + MyID.ToString();
                    break;
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            return  MyNewID;          
        }

        private void 出勤ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "/";
        }
        private void 迟到ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = ">";
        }

        private void 产假ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "√";
        }

        private void 早退ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "<";
        }

        private void 事假ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "#";
        }

        private void 病假ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "+";
        }

        private void 婚假ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "△";
        }

        private void 旷工ToolStripButton_Click(object sender, EventArgs e)
        {
            if ((this.考勤记录DataGridView.CurrentCell.ColumnIndex == 2) || (this.考勤记录DataGridView.CurrentCell.ColumnIndex == 1))
                return;
            this.考勤记录DataGridView.CurrentCell.Value = "×";
        }

        private void 打印ToolStripButton_Click(object sender, EventArgs e)
        {
            //System.Data.DataTable MyQueryTable = new System.Data.DataTable();
            //MyQueryTable = this.myPersonnelDataSet.考勤记录.Copy();
            //if (MyQueryTable.Rows.Count < 1)
            //{
            //    return;
            //}
            ////导出Excel表格数据文件
            //ApplicationClass MyExcel;
            //Workbooks MyWorkBooks;
            //Workbook MyWorkBook;
            //Worksheet MyWorkSheet;
            //// char MyColumns;
            //Range MyRange;
            //Object[,] MyData = new Object[500, 35];
            //int i, j;
            //MyExcel = new ApplicationClass();
            //MyExcel.Visible = true;
            //if (MyExcel == null)
            //{
            //    MessageBox.Show("Excel程序无法启动!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            //MyWorkBooks = MyExcel.Workbooks;
            //MyWorkBook = MyWorkBooks.Add(Missing.Value);
            //MyWorkSheet = (Worksheet)MyWorkBook.Worksheets[1];
            //MyRange = MyWorkSheet.get_Range("A5", "AF5");
            //MyData[0, 0] = "姓名";
            //for (i = 1; i < 32; i++)
            //{
            //    MyData[0, i] = i.ToString();
            //}
            //j = 1;
            ////输出数据库记录
            //foreach (DataRow MyRow in MyQueryTable.Rows)
            //{
            //    for (i = 2; i < MyQueryTable.Columns.Count - 1; i++)
            //    {
            //        MyData[j, i - 2] = MyRow[i].ToString();
            //    }
            //    j++;
            //}
            //MyRange = MyRange.get_Resize(MyQueryTable.Rows.Count+1, 32);
            //MyRange.Value2 = MyData;
            //MyRange.EntireColumn.AutoFit();
            //MyWorkSheet.Cells[2, 2] = this.MyCompany + this.部门ToolStripComboBox.Text + "考勤表";
            //MyWorkSheet.Cells[4, 1] = "考勤日期:" + this.考勤年份ToolStripComboBox.Text + "年"+this.月份ToolStripComboBox.Text+"月份";
            //MyWorkSheet.Cells[MyQueryTable.Rows.Count + 7, 1] = "考勤符号说明:出勤 /, 迟到>, 早退<, 产假√,事假#,病假+,婚假△,旷工×";
         }      
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -