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

📄 computeform.cs

📁 c# 人事工资管理系统平台,很好用嘎..你们看看参考
💻 CS
📖 第 1 页 / 共 2 页
字号:
//文件名:ComputeForm.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 ComputeForm : Form
    {
        public ComputeForm()
        {
            InitializeComponent();
        }
        public string MyCompany;
        private void ComputeForm_Load(object sender, EventArgs e)
        {
            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 员工编号 NOT IN (SELECT 员工编号 FROM 工资核算表)";
            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();
                float My基本工资 =(float)Convert.ToDouble(MyRow[17].ToString());
                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.Float));

                MyCommand.Parameters["@自编号"].Value = My自编号;
                MyCommand.Parameters["@员工编号"].Value = My员工编号;
                MyCommand.Parameters["@员工姓名"].Value = My员工姓名;
                MyCommand.Parameters["@基本工资"].Value = My基本工资;
                MyCommand.ExecuteNonQuery();
            }       
            //获取公司的部门信息            
            System.Data.DataTable MyDepartmentTable = new System.Data.DataTable();
            MySQL = "Select 部门名称 From 公司部门";
            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();
            }
            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());
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
        }
        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 = "HS0000000" + MyID.ToString();
                    break;
                case 2:
                    MyNewID = "HS000000" + MyID.ToString();
                    break;
                case 3:
                    MyNewID = "HS00000" + MyID.ToString();
                    break;
                case 4:
                    MyNewID = "HS0000" + MyID.ToString();
                    break;
                case 5:
                    MyNewID = "HS000" + MyID.ToString();
                    break;
                case 6:
                    MyNewID = "HS00" + MyID.ToString();
                    break;
                case 7:
                    MyNewID = "HS0" + MyID.ToString();
                    break;
            }
            if (MyConnection.State == ConnectionState.Open)
            {
                MyConnection.Close();
            }
            return MyNewID;
        }

        private void 工资核算表BindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.工资核算表BindingSource.EndEdit();
            this.工资核算表TableAdapter.Update(this.myPersonnelDataSet.工资核算表);

        }

        private void 查询ToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.工资核算表TableAdapter.FillBy(this.myPersonnelDataSet.工资核算表, 部门ToolStripComboBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        private void 打印ToolStripButton_Click(object sender, EventArgs e)
        {
            ////导出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];
            //MyColumns = (char)(this.myPersonnelDataSet.工资核算表.Columns.Count + 64);

⌨️ 快捷键说明

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