コード例 #1
0
        private void Confirm_Click(object sender, EventArgs e)    //确认添加按钮事件
        {
            LinkSQL linksql = new LinkSQL();
            //System.Data.SqlClient.SqlDataReader RD;
            int i;

            linksql.OpenSQL();
            try
            {
                i = linksql.SQLInsert(@"insert sign(employee_ID,employee_Name) values('" + employee_ID.Text + "','" + name.Text + "')");
                if (i == 1)
                {
                    i = linksql.SQLInsert(@"insert employee values('" + department_ID.Text + "','" + employee_ID.Text + "','" + name.Text + "','" + sex.Text + "'," + float.Parse(wages.Text) + ",'" + IDCard.Text + "','" + address.Text + "','" + telephone.Text + "','" + post.Text + "','" + DateTime.Now.ToString() + "')");
                    if (i == 1)
                    {
                        MessageBox.Show("添加成功!", "提示"); this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加失败", "提示"); return;
                    }
                }
                else
                {
                    MessageBox.Show("添加失败!", "提示"); return;
                }
            }
            catch
            {
                MessageBox.Show("添加失败,请检查您输入的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return;
            }
            linksql.CloseSQL();
        }
コード例 #2
0
        private void BulletinContentChange_Click(object sender, EventArgs e)   //当光标离开公告栏的textBox时发生
        {
            LinkSQL      linksql = new LinkSQL();
            DialogResult dr      = MessageBox.Show("确认修改?", "修改公告", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

            if (dr == DialogResult.OK)
            {
                try
                {
                    linksql.OpenSQL();       //打开数据库
                    int i = 0;
                    if (label4.Text == "采购部")
                    {
                        i = linksql.SQLInsert(@"insert notice values('PU0001',GETDATE(),'" + BulletinBoardCententText.Text + "')");
                    }
                    if (label4.Text == "仓储部")
                    {
                        i = linksql.SQLInsert(@"insert notice values('ST0001',GETDATE(),'" + BulletinBoardCententText.Text + "')");
                    }
                    if (i > 0)
                    {
                        MessageBox.Show("修改成功!", "修改结果");
                        if (label4.Text == "采购部")
                        {
                            linksql.SQLSelect(@"select content from notice where department_id = 'PU0001' order by date desc");
                            BulletinBoardCentent.Text = linksql.Comm.ExecuteScalar().ToString();
                        }
                        if (label4.Text == "仓储部")
                        {
                            linksql.SQLSelect(@"select content from notice where department_id = 'ST0001' order by date desc");
                            BulletinBoardCentent.Text = linksql.Comm.ExecuteScalar().ToString();
                        }
                    }
                    else
                    {
                        MessageBox.Show("修改失败!请重新修改!", "修改结果", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                    linksql.CloseSQL();
                }
                catch
                {
                    string str = BulletinBoardCententText.Text;
                    dr = MessageBox.Show("本次修改将不进行保存,是否依然修改?", "修改结果", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    if (dr == DialogResult.OK)
                    {
                        BulletinBoardCentent.Text = str;
                    }
                }
                BulletinBoardCentent.Visible     = true;
                BulletinBoardCententText.Visible = false;
                updateNotice.Text = "修改公告";
            }
            else
            {
                MessageBox.Show("修改失败!您取消了修改!", "修改提示");
                BulletinBoardCentent.Visible     = true;
                BulletinBoardCententText.Visible = false;
                updateNotice.Text = "修改公告";
            }
        }
コード例 #3
0
        /// <summary>
        /// 删除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteData(object sender, EventArgs e)
        {
            DialogResult Re = MessageBox.Show("确认删除?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (Re == DialogResult.OK)
            {
                int     No      = int.Parse(((Button)sender).Name); //获取要删除的数据所在行
                int     y       = 0;                                //找出要删除的行
                LinkSQL linkSql = new LinkSQL();
                try
                {
                    linkSql.OpenSQL();
                }
                catch
                {
                    MessageBox.Show("无法连接数据库!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                linkSql.SQLSelect(@"select No from demand");
                System.Data.SqlClient.SqlDataReader DR = linkSql.Comm.ExecuteReader();
                while (DR.Read())
                {
                    y++;
                    if (y == No)
                    {
                        No = int.Parse(DR[0].ToString());
                    }
                }
                linkSql.CloseSQL();
                try
                {
                    linkSql.OpenSQL();
                }
                catch
                {
                    MessageBox.Show("无法连接数据库!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                linkSql.SQLInsert(@"delete demand where No = " + No.ToString());
                linkSql.SQLSelect(@"dbcc checkident('demand',reseed,0)");
                linkSql.Comm.ExecuteNonQuery();
                linkSql.CloseSQL();
                RefreshData();
            }
            else
            {
                return;
            }
        }
コード例 #4
0
        private void AddData()
        {
            int     i = 0, k = 0; //i记录影响行数,K记录重复行数
            string  insertStr = @"insert demand values('" + department_ID.Text + "','" + post.Text + "'," + rec_Number.Text + ",'" + explain.Text + "')";
            LinkSQL linksql   = new LinkSQL();

            try
            {
                linksql.OpenSQL();
                linksql.SQLSelect("select count(*) from demand where post = '" + post.Text + "'");
                k = int.Parse(linksql.Comm.ExecuteScalar().ToString());
                linksql.SQLSelect("select NO from demand where post = '" + post.Text + "'");
                linksql.CloseSQL();//关闭连接
                if (k == 0)
                {
                    linksql.OpenSQL();  //打开连接
                    i = linksql.SQLInsert(insertStr);
                    linksql.CloseSQL(); //关闭连接
                }
                else
                {
                    linksql.OpenSQL();//打开连接
                    My.MyMessageBox messageBox = new My.MyMessageBox();
                    messageBox.Show("该信息已存在,是否修改招聘信息?", "提示", My.MyMessageBox.MyMessageBoxButton.OKCancel, My.MyMessageBox.MyMessageBoxIcon.Question);
                    DialogResult DR = messageBox.DialogResult;
                    if (DR == DialogResult.Cancel)
                    {
                        this.Close();
                    }
                    else
                    {
                        //upDateNO = int.Parse(linksql.Comm.ExecuteScalar().ToString());
                        string upDateStr = @"update demand set department_id = '" + department_ID.Text + "',post = '" + post.Text + "',rec_Number = " + rec_Number.Text + ",exlain = '" + explain.Text + "' where NO = " + upDateNO.ToString();
                        i = linksql.SQLInsert(upDateStr);
                    }
                    linksql.CloseSQL();//关闭连接
                }
            }
            catch       //插入或更新出错尝试重新插入更新(20次)
            {
                linksql.CloseSQL();
                linksql.OpenSQL();//打开连接
                //upDateNO = int.Parse(linksql.Comm.ExecuteScalar().ToString());
                string upDateStr = @"update demand set department_id = '" + department_ID.Text + "',post = '" + post.Text + "',rec_Number = " + rec_Number.Text + ",exlain = '" + explain.Text + "' where NO = " + upDateNO.ToString();
                for (int x = 0; x < 20; x++)
                {
                    try
                    {
                        if (k == 0)
                        {
                            i = linksql.SQLInsert(insertStr); break;
                        }
                        else
                        {
                            i = linksql.SQLInsert(upDateStr);
                        }
                    }
                    catch { continue; }
                }
                linksql.CloseSQL();
                if (i == 1)
                {
                    MessageBox.Show("添加成功!", "提示");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("插入失败,请重试!如多次提示,请尝试删除一个招聘信息后再次修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                return;
            }
            linksql.CloseSQL();
            if (i == 1)//判断添加数据结果
            {
                MessageBox.Show("添加成功!", "提示");
                this.Close();
            }
            else
            {
                MessageBox.Show("插入失败,请重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
コード例 #5
0
        /// <summary>
        /// 确认提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            /// <summary>受影响的行数 </summary>
            int     infRow  = 0; //受影响的行数
            int     repeat  = 0; //重复的数据数
            LinkSQL linkSql = new LinkSQL();

            try
            {
                try
                {
                    //--------------------
                    linkSql.OpenSQL();
                    linkSql.SQLSelect(@"select count(*) from applicants where ID_card = '" + id.Text + "' ");
                    repeat = int.Parse(linkSql.Comm.ExecuteScalar().ToString());
                    linkSql.Conn.Dispose();
                    linkSql.Comm.Dispose();
                    linkSql.CloseSQL();
                    //----------------------查询库中是否已存在数据
                }
                catch { MessageBox.Show("无法连接服务器,请重试"); return; }
                if (repeat == 0)
                {
                    linkSql.OpenSQL();
                    string insertStr = "insert into applicants values('" + name.Text + "','" + sex.Text + "'," + age.Text + ",'" + id.Text + "','" + post.Text + "','" + joinTime.Text + "')";
                    infRow = linkSql.SQLInsert(insertStr);
                    linkSql.Comm.Dispose();
                    linkSql.Conn.Dispose();
                    linkSql.CloseSQL();
                }
                else
                {
                    MessageBox.Show("已存在此人,请勿插入重复数据!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
                }
            }
            catch
            {
                MessageBox.Show("插入失败,请重试!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                linkSql.Conn.Dispose();
                linkSql.Comm.Dispose();
            }
            if (infRow == 1)
            {
                MessageBox.Show("添加成功!", "提示");
                foreach (Control a in this.Controls)
                {
                    if (a.GetType().Name == "TextBox")
                    {
                        a.Text = "";
                    }
                }
            }
            else
            {
                MessageBox.Show("添加失败", "提示");
                return;
            }
        }
コード例 #6
0
        private void PutIn_Click(Label[] tableLabel)//确认提交
        {
            int index = 0;

            string[] tablelabelName = new string[16];
            int[]    tableboxValue  = new int[16];

            while (textBoxName[index] != null)
            {
                switch (textBoxName[index])
                {
                case "tableTextBox1_0":
                    tableboxValue[index]  = int.Parse(tableTextBox1[0].Text);
                    tablelabelName[index] = tableLabel[0].Text;
                    break;

                case "tableTextBox1_1":
                    tableboxValue[index]  = int.Parse(tableTextBox1[1].Text);
                    tablelabelName[index] = tableLabel[0].Text;
                    break;

                case "tableTextBox1_2":
                    tableboxValue[index]  = int.Parse(tableTextBox1[2].Text);
                    tablelabelName[index] = tableLabel[5].Text;
                    break;

                case "tableTextBox1_3":
                    tableboxValue[index]  = int.Parse(tableTextBox1[3].Text);
                    tablelabelName[index] = tableLabel[5].Text;
                    break;

                case "tableTextBox1_4":
                    tableboxValue[index]  = int.Parse(tableTextBox1[4].Text);
                    tablelabelName[index] = tableLabel[10].Text;
                    break;

                case "tableTextBox1_5":
                    tableboxValue[index]  = int.Parse(tableTextBox1[5].Text);
                    tablelabelName[index] = tableLabel[10].Text;
                    break;

                case "tableTextBox1_6":
                    tableboxValue[index]  = int.Parse(tableTextBox1[6].Text);
                    tablelabelName[index] = tableLabel[15].Text;
                    break;

                case "tableTextBox1_7":
                    tableboxValue[index]  = int.Parse(tableTextBox1[7].Text);
                    tablelabelName[index] = tableLabel[15].Text;
                    break;

                case "tableTextBox1_8":
                    tableboxValue[index]  = int.Parse(tableTextBox1[8].Text);
                    tablelabelName[index] = tableLabel1[20].Text;
                    break;

                case "tableTextBox1_9":
                    tableboxValue[index]  = int.Parse(tableTextBox1[9].Text);
                    tablelabelName[index] = tableLabel1[20].Text;
                    break;

                case "tableTextBox1_10":
                    tableboxValue[index]  = int.Parse(tableTextBox1[10].Text);
                    tablelabelName[index] = tableLabel1[25].Text;
                    break;

                case "tableTextBox1_11":
                    tableboxValue[index]  = int.Parse(tableTextBox1[11].Text);
                    tablelabelName[index] = tableLabel1[25].Text;
                    break;

                case "tableTextBox1_12":
                    tableboxValue[index]  = int.Parse(tableTextBox1[12].Text);
                    tablelabelName[index] = tableLabel1[30].Text;
                    break;

                case "tableTextBox1_13":
                    tableboxValue[index]  = int.Parse(tableTextBox1[13].Text);
                    tablelabelName[index] = tableLabel1[30].Text;
                    break;

                case "tableTextBox1_14":
                    tableboxValue[index]  = int.Parse(tableTextBox1[14].Text);
                    tablelabelName[index] = tableLabel1[35].Text;
                    break;

                case "tableTextBox1_15":
                    tableboxValue[index]  = int.Parse(tableTextBox1[15].Text);
                    tablelabelName[index] = tableLabel1[35].Text;
                    break;
                }
                index++;
            }
            DialogResult dr = MessageBox.Show("确认提交信息?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dr == DialogResult.OK)
            {
                int     x = 0, sum = 0;
                LinkSQL linksql = new LinkSQL();
                linksql.OpenSQL();
                for (int i = 0; tablelabelName[i] != null /*tableTextBox1[i * 2].Visible == true*/; i++)
                {
                    foreach (Label a in tableLabel1)
                    {
                        if (a.Text == tablelabelName[i])
                        {
                            if (label12.Text == "alter2")    //判断当前触修改的列
                            {
                                x += linksql.SQLInsert(@"update sign set SHC = " + tableboxValue[i] + " where employee_ID = '" + a.Text + "'");
                            }
                            if (label12.Text == "alter3")    //判断当前触修改的列
                            {
                                x += linksql.SQLInsert(@"update sign set sign_in = " + tableboxValue[i] + " where employee_ID = '" + a.Text + "'");
                            }
                        }
                    }
                    foreach (Label a in tableLabel2)
                    {
                        if (a.Text == tablelabelName[i])
                        {
                            if (label12.Text == "alter2")    //判断当前触修改的列
                            {
                                x += linksql.SQLInsert(@"update sign set SHC = " + tableboxValue[i] + " where employee_ID = '" + a.Text + "'");
                            }
                            if (label12.Text == "alter3")    //判断当前触修改的列
                            {
                                x += linksql.SQLInsert(@"update sign set sign_in = " + tableboxValue[i] + " where employee_ID = '" + a.Text + "'");
                            }
                        }
                    }
                    sum += 1;
                }
                linksql.CloseSQL();
                if (sum == x && sum != 0)
                {
                    MessageBox.Show("修改成功", "修改结果");
                }
                else if (sum != 0 && (sum - x) == 0)
                {
                    MessageBox.Show("修改失败", "修改结果");
                }
                else if (sum == 0)
                {
                    MessageBox.Show("未发生改变", "提示");
                }
                else
                {
                    MessageBox.Show("出现故障,请自行检查!\n修改成功" + x.ToString() + "条," + (sum - x).ToString() + "条", "修改结果", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                return;
            }
            s = 0;
            foreach (TextBox a in tableTextBox1)
            {
                a.Leave       -= TextBoxLevel_Click;
                a.TextChanged -= TextBoxChange_Click;
            }

            Initial_Data();
            Initial_BaseData();     //刷新显示
            textBoxName = new string[16];
        }