Exemplo n.º 1
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            //封装数组
            TextBox[] txt     = { txt_num, txt_name, txt_student_num, txt_phone, txt_position };
            string[]  message = { "职工编号", "职工姓名", "学号", "联系方式", "职位" };
            string    mysql   = "";

            //操作提示
            for (int i = 0; i < txt.Length; i++)
            {
                if (is_empty(txt[i].Text.Trim()))
                {
                    MessageBox.Show("请输入" + message[i] + "!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }


            //初始化数据
            worker1.worker_num  = txt_num.Text.Trim();
            worker1.name        = txt_name.Text.Trim();
            worker1.student_num = txt_student_num.Text.Trim();
            worker1.subject     = cbo_subject.Text.Trim();
            worker1.phone       = txt_phone.Text.Trim();
            worker1.position    = txt_position.Text.Trim();
            if (rdo_man.Checked == true)
            {
                worker1.sex = "男";
            }
            rdo_man.Checked = true;
            if (rdo_woman.Checked == true)
            {
                worker1.sex = "女";
            }
            worker1.isleave     = cbo_yesno.SelectedItem.ToString();
            worker1.month_score = txt_month.Text.Trim();
            worker1.total_score = txt_total.Text.Trim();

            //插入新家教信息
            if (insertstate == true)
            {
                mysql = "insert into worker " + insert_worker_str + " values " + worker1.connectstr();
                DialogResult result = MessageBox.Show("确认新增职工信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                        mysql = string.Format("insert into user (username,password,degree) values ('{0}','{1}','{2}')",
                                              worker1.worker_num, worker1.student_num, "操作员");
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("新增成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }


            //更新保存现有家教信息
            else
            {
                mysql = worker1.updatestr();
                DialogResult result = MessageBox.Show("确认更新职工信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("更新成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }
        }
        /// <summary>
        /// 新增或更新家教信息  标志位insertnum
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_save_Click(object sender, EventArgs e)
        {
            string history = "";

            //封装数组
            TextBox[] txt = { txt_parent_num, txt_print_num,   txt_parent_name, txt_phone, txt_sadd, txt_dadd,
                              txt_grade_stu,  txt_subject_stu, txt_tutor_price, txt_tutor_time };
            string[]  message = { "家长编号", "打印编号", "家长称呼", "联系电话", "家长地址(简单)", "家长地址(详细)", "年级", "科目",
                                  "家教价格",  "家教时间" };
            string    mysql = "";

            //操作提示
            for (int i = 0; i < txt.Length; i++)
            {
                if (is_empty(txt[i].Text.Trim()))
                {
                    MessageBox.Show("请输入" + message[i] + "!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            if (is_empty(cbo_reception.SelectedItem.ToString()))
            {
                MessageBox.Show("请选择接待人!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (rdo_woman.Checked == false && rdo_man.Checked == false)
            {
                MessageBox.Show("请选择学员性别!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            //初始化数据
            //判断科目是否被更改
            bool subject_changed = false;

            if (tutoring1.subject_stu != txt_subject_stu.Text.Trim())
            {
                subject_changed = true;
            }

            updateinfo(ref history, ref tutoring1.parent_num, txt_parent_num.Text.Trim());
            updateinfo(ref history, ref tutoring1.print_num, txt_print_num.Text.Trim());
            updateinfo(ref history, ref tutoring1.parent_name, txt_parent_name.Text.Trim());
            updateinfo(ref history, ref tutoring1.reception, cbo_reception.SelectedItem.ToString());
            updateinfo(ref history, ref tutoring1.phone, txt_phone.Text.Trim());
            updateinfo(ref history, ref tutoring1.simple_adr, txt_sadd.Text.Trim());
            updateinfo(ref history, ref tutoring1.detail_adr, txt_dadd.Text.Trim());
            updateinfo(ref history, ref tutoring1.grade_stu, txt_grade_stu.Text.Trim());
            updateinfo(ref history, ref tutoring1.subject_stu, txt_subject_stu.Text.Trim());
            tutoring1.reception_time = dt_recepiton_time.Value.ToString();

            /*tutoring1.parent_num = txt_parent_num.Text.Trim();
             * tutoring1.print_num = txt_print_num.Text.Trim();
             * tutoring1.reception = cbo_reception.SelectedItem.ToString();
             *
             * tutoring1.parent_name = txt_parent_name.Text.Trim();
             * tutoring1.phone = txt_phone.Text.Trim();
             * tutoring1.simple_adr = txt_sadd.Text.Trim();
             * tutoring1.detail_adr = txt_dadd.Text.Trim();
             * tutoring1.grade_stu = txt_grade_stu.Text.Trim();
             * tutoring1.subject_stu = txt_subject_stu.Text.Trim();*/
            if (rdo_man.Checked == true)
            {
                tutoring1.student_sex = "男";
            }
            if (rdo_woman.Checked == true)
            {
                tutoring1.student_sex = "女";
            }


            updateinfo(ref history, ref tutoring1.tutors_price, txt_tutor_price.Text.Trim());
            updateinfo(ref history, ref tutoring1.tutors_time, txt_tutor_time.Text.Trim());
            updateinfo(ref history, ref tutoring1.sex, cbo_sex.SelectedItem.ToString());
            updateinfo(ref history, ref tutoring1.place, txt_place.Text.Trim());
            updateinfo(ref history, ref tutoring1.grade, txt_grade.Text.Trim());
            updateinfo(ref history, ref tutoring1.subject, txt_subject.Text.Trim());
            updateinfo(ref history, ref tutoring1.other_requests, txt_other_requests.Text.Trim());

            /*tutoring1.tutors_price = txt_tutor_price.Text.Trim();
             * tutoring1.tutors_time = txt_tutor_time.Text.Trim();
             * tutoring1.sex = cbo_sex.SelectedItem.ToString();
             * tutoring1.place = txt_place.Text.Trim();
             * tutoring1.grade = txt_grade.Text.Trim();
             * tutoring1.subject = txt_subject.Text.Trim();
             * tutoring1.other_requests = txt_other_requests.Text.Trim();*/


            bool payment_changed = false;

            if (tutoring1.payment_state != "已缴" && cbo_payment_state.SelectedItem.ToString() == "已缴")
            {
                payment_changed = true;
            }
            updateinfo(ref history, ref tutoring1.payment_state, cbo_payment_state.SelectedItem.ToString());
            //tutoring1.payment_state = cbo_payment_state.SelectedItem.ToString();
            subject = tutoring1.subject_stu.Split('、');
            if (tutoring1.payment_state != "已缴")
            {
                tutoring1.payment_time = null;
            }
            else
            {
                tutoring1.payment_time = dt_payment_time.Value.ToString();
            }


            tutoring1.latest_time = DateTime.Now.ToString();

            //插入新家教信息
            if (insertstate == true)
            {
                tutoring1.tutor_state = "接入";
                tutoring1.remarks     = "";

                mysql = "insert into tutoring " + insert_tutoring_str + " values " + tutoring1.connectstr();
                DialogResult result = MessageBox.Show("确认新增家教信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                        Console.WriteLine(history);
                        mysql = string.Format("insert into history (user,optype,num,time,content) values ('{0}', '{1}', '{2}', '{3}','{4}')",
                                              user, "新增家教信息", tutoring1.print_num, DateTime.Now.ToString(), history);
                        Console.WriteLine(mysql);
                        mydb.ExecuteNonQuery(mysql);
                        if (tutoring1.payment_time != null)
                        {
                            mydb.update_payment_date(tutoring1.print_num, tutoring1.payment_time);
                            if (payment_changed == true)
                            {
                                mysql = string.Format("insert into history (user,optype,num,time) values ('{0}', '{1}', '{2}', '{3}')",
                                                      user, "缴费", tutoring1.print_num, DateTime.Now.ToString());
                                mydb.ExecuteNonQuery(mysql);
                            }
                        }
                        for (int i = 0; i < subject.Length; i++)
                        {
                            //string insert_business_str = "(print_num,tutor_num,subject,state,time,reception,remarks,now";
                            mysql = string.Format("insert into business (print_num,subject,time,reception) values ('{0}', '{1}', '{2}', '{3}')",
                                                  tutoring1.print_num, subject[i], DateTime.Now.ToString(), tutoring1.reception);

                            mydb.ExecuteNonQuery(mysql);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("保存成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }


            //更新保存现有家教信息
            else
            {
                mysql = tutoring1.updatestr();

                DialogResult result = MessageBox.Show("确认更新家教信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                        mysql = string.Format("insert into history (user,optype,num,time,content) values ('{0}', '{1}', '{2}', '{3}','{4}')",
                                              user, "更新家教信息", tutoring1.print_num, DateTime.Now.ToString(), history);
                        mydb.ExecuteNonQuery(mysql);
                        if (tutoring1.payment_time != null)
                        {
                            mydb.update_payment_date(tutoring1.print_num, tutoring1.payment_time);
                            if (payment_changed == true)
                            {
                                mysql = string.Format("insert into history (user,optype,num,time) values ('{0}', '{1}', '{2}', '{3}')",
                                                      user, "缴费", tutoring1.print_num, DateTime.Now.ToString());
                                mydb.ExecuteNonQuery(mysql);
                            }
                        }


                        ///更新关于科目的更更改
                        ///
                        if (subject_changed == true)
                        {
                            string temp = "";
                            for (int i = 0; i < subject.Length; i++)
                            {
                                mysql = string.Format("insert into business(print_num, subject, time) select '{0}','{1}','{2}' from dual " +
                                                      "where not exists(select 1 from business where print_num = '{3}' and subject ='{4}')", tutoring1.print_num,
                                                      subject[i], DateTime.Now.ToString(), tutoring1.print_num, subject[i]);
                                temp += "'" + subject[i] + "',";
                                mydb.ExecuteNonQuery(mysql);
                            }

                            temp  = temp.Substring(0, temp.Length - 1);
                            mysql = "update business set now=0 where print_num='" + tutoring1.print_num +
                                    "' and subject not in(" + temp + ")";
                            Console.WriteLine(mysql);
                            mydb.ExecuteNonQuery(mysql);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("更新成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 新增或更新教员信息  标志位insertstate
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_save_Click(object sender, EventArgs e)
        {
            //封装数组
            TextBox[] txt     = { txt_num, txt_student_name, txt_student_num, txt_phone, txt_place };
            string[]  message = { "教员编号", "教员姓名", "学号", "联系方式", "生源地" };
            string    mysql   = "";

            //操作提示
            for (int i = 0; i < txt.Length; i++)
            {
                if (is_empty(txt[i].Text.Trim()))
                {
                    MessageBox.Show("请输入" + message[i] + "!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }


            //初始化数据
            tutor1.tutor_num   = txt_num.Text.Trim();
            tutor1.name        = txt_student_name.Text.Trim();
            tutor1.student_num = txt_student_num.Text.Trim();
            tutor1.subject     = cbo_subject.Text.Trim();
            tutor1.degree      = cbo_degree.SelectedItem.ToString();
            tutor1.phone       = txt_phone.Text.Trim();
            tutor1.place       = txt_place.Text.Trim();
            if (rdo_man.Checked == true)
            {
                tutor1.sex = "男";
            }
            rdo_man.Checked = true;
            if (rdo_woman.Checked == true)
            {
                tutor1.sex = "女";
            }
            tutor1.remarks    = txt_important_remarks.Text.Trim();
            tutor1.blacklist  = cbo_yesno.SelectedItem.ToString();
            tutor1.explantion = txt_imprisonment.Text.Trim();


            //插入新家教信息
            if (insertstate == true)
            {
                mysql = "insert into tutor " + insert_tutor_str + " values " + tutor1.connectstr();
                Console.WriteLine(mysql);
                DialogResult result = MessageBox.Show("确认新增教员信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("新增成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }


            //更新保存现有家教信息
            else
            {
                mysql = tutor1.updatestr();
                Console.WriteLine(mysql);
                DialogResult result = MessageBox.Show("确认更新教员信息?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("更新成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }
        }
Exemplo n.º 4
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            //封装数组
            TextBox[] txt     = { txt_username, txt_password };
            string[]  message = { "用户名", "密码" };
            string    mysql   = "";

            //操作提示
            for (int i = 0; i < txt.Length; i++)
            {
                if (is_empty(txt[i].Text.Trim()))
                {
                    MessageBox.Show("请输入" + message[i] + "!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            //初始化数据
            username = txt_username.Text.Trim();
            password = txt_password.Text.Trim();
            level    = cbo_degree.SelectedItem.ToString();

            //插入新信息
            if (insertstate == true)
            {
                mysql = string.Format("insert into user (username,password,degree) values ('{0}','{1}','{2}')", username, password, level);
                DialogResult result = MessageBox.Show("确认新增?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("新增成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }


            //更新保存现有家教信息
            else
            {
                mysql = "update user set password='******',degree='" + level + "' where username='******'";
                DialogResult result = MessageBox.Show("确认更新?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                else
                {
                    try
                    {
                        mydb.ExecuteNonQuery(mysql);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "操作数据库出错!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    MessageBox.Show("更新成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    dgvfresh();
                }
            }
        }