コード例 #1
0
ファイル: MenuForm.cs プロジェクト: chinnaphat25/TIS
        public void MenuForm_Load(object sender, EventArgs e)
        {
            label2.Text  = "ฝ่ายบริหารการจัดเก็บเงินค่าธรรมเนียม กองทางหลวงพิเศษระหว่างเมือง\r\n";
            label2.Text += "Application : " + Application.ProductName;
            label2.Text += "\r\nVersion : " + Application.ProductVersion;
            script.Set_Max_Connection();
            FileInfo DirInfo = new FileInfo(script.file_conf);

            if (!DirInfo.Exists)
            {
                MessageBox.Show("ไม่พบการเชื่อมต่อฐานข้อมูล กรุณา 'ตั้งค่า' ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //server=localhost;database=testDB;uid=root;pwd=abc123;
                //this.Close();
                btn_around.Enabled  = false;
                btn_bag.Enabled     = false;
                btn_send.Enabled    = false;
                btn_edit.Enabled    = false;
                button1.Enabled     = false;
                btn_refund.Enabled  = false;
                btn_memo.Enabled    = false;
                btn_report.Enabled  = false;
                btn_setting.Enabled = true;
                button2.Enabled     = false;
                button3.Enabled     = false;
            }
            else
            {
                try
                {
                    /*FileInfo DirInfo1 = new FileInfo(script.file_around);
                     * if (!DirInfo1.Exists)
                     * {
                     *  btn_around.Image = Properties.Resources.success;
                     *  btn_around.Text = "เปิดกะ";
                     *  aroundStatus = true;
                     * }
                     * else
                     * {
                     *  btn_around.Image = Properties.Resources.error;
                     *  btn_around.Text = "ปิดกะ";
                     *  aroundStatus = false;
                     * }*/

                    FileInfo DirInfo2    = new FileInfo(script.file_cpoint);
                    FileInfo DirInfo3    = new FileInfo(script.file_Straps);
                    bool     cpoint_file = false;
                    if (DirInfo2.Exists && DirInfo3.Exists)
                    {
                        cpoint_file = true;
                        string[]        cpoint = File.ReadAllText(@script.file_cpoint).Split('|');
                        string          sql    = "SELECT * FROM tbl_cpoint WHERE tbl_cpoint_id =  '" + cpoint[0] + "'";
                        ConnectDB       contxt = new ConnectDB();
                        MySqlConnection conn   = new MySqlConnection();
                        conn = new MySqlConnection(contxt.context());
                        MySqlCommand cmd = new MySqlCommand(sql, conn);
                        //conn.Close();
                        conn.Open();
                        MySqlDataReader reader = cmd.ExecuteReader();
                        try
                        {
                            if (reader.Read())
                            {
                                if (!reader.IsDBNull(0))
                                {
                                    line9                  = File.ReadAllText(script.file_cpoint).Split('|')[3];
                                    lb_cpoint.Text         = cpoint[0] + "  ด่าน" + reader.GetString("tbl_cpoint_name") + " " + (line9 != "9" ? cpoint[1] : "") + "   ";
                                    cpoint_id              = cpoint[0];
                                    sub_cpoint             = cpoint[1];
                                    lb_time.ForeColor      = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    groupBox1.ForeColor    = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    lb_cpoint.ForeColor    = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    group_around.ForeColor = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    lb_emp_name.ForeColor  = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    label_date.ForeColor   = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                    lb_group.ForeColor     = ColorTranslator.FromHtml(reader.GetString("tbl_cpoint_color"));
                                }
                            }
                            else
                            {
                                lb_cpoint.Text     = "ไม่พบข้อมูลด่าน";
                                btn_around.Enabled = false;
                            }
                            reader.Close();
                        }
                        catch
                        {
                        }
                        conn.Close();
                    }
                    else
                    {
                        btn_around.Enabled  = false;
                        btn_bag.Enabled     = false;
                        btn_send.Enabled    = false;
                        btn_edit.Enabled    = false;
                        btn_report.Enabled  = false;
                        btn_refund.Enabled  = false;
                        btn_memo.Enabled    = false;
                        button1.Enabled     = false;
                        button2.Enabled     = false;
                        button3.Enabled     = false;
                        btn_setting.Enabled = false;
                    }

                    if (cpoint_file)
                    {
                        if (File.ReadAllText(@script.file_cpoint).Split('|')[2] != "1")
                        {
                            /*if (aroundStatus)
                             * {
                             *  btn_bag.Enabled = false;
                             *  btn_send.Enabled = false;
                             *  btn_edit.Enabled = false;
                             *  button1.Enabled = false;
                             *  group_around.Visible = false;
                             *  button2.Enabled = false;
                             *  button3.Enabled = false;
                             *  btn_report.Enabled = false;
                             * }
                             * else
                             * {*/

                            Script script = new Script();
                            try
                            {
                                string[] around = File.ReadAllText(script.file_around).Split('|');
                                around_num = around[1];
                                //string emp_control = script.Select_SQL();
                                emp_control_id = around[0];
                            }
                            catch { }
                            //around_num = around[1];
                            string          sql    = "SELECT * FROM tbl_status_around JOIN tbl_emp e ON tbl_status_around_emp_open_id = tbl_emp_id JOIN tbl_emp_group g ON e.tbl_emp_group_id = g.tbl_emp_group_id WHERE tbl_status_around_close = '0' AND tbl_status_around_cpoint_id = '" + cpoint_id + "' AND tbl_status_around_cpoint_sub_id = '" + sub_cpoint + "'";
                            ConnectDB       contxt = new ConnectDB();
                            MySqlConnection conn   = new MySqlConnection();
                            conn = new MySqlConnection(contxt.context());
                            MySqlCommand cmd = new MySqlCommand(sql, conn);
                            conn.Open();
                            MySqlDataReader reader = cmd.ExecuteReader();
                            try
                            {
                                if (reader.Read())
                                {
                                    if (!reader.IsDBNull(0))
                                    {
                                        label_date.Text  = script.GetMontThai(script.DateTimeParse(reader.GetString("tbl_status_around_date")));
                                        lb_emp_name.Text = reader.GetString("tbl_emp_name");
                                        label_date.Text += "  " + script.GetAroundName(reader.GetString("tbl_status_around_aid"));
                                        lb_group.Text    = reader.GetString("tbl_emp_group_name");
                                        around           = int.Parse(reader.GetString("tbl_status_around_aid"));

                                        //string[] aid = File.ReadAllText(@"around.txt").Split('|');
                                        string sql_check_straps = "SELECT * FROM `tbl_income` JOIN `tbl_status_around` ON `tbl_income_around_id` = `tbl_status_around_id` JOIN `tbl_emp` ON `tbl_emp_id` = `tbl_income_emp_id` WHERE tbl_status_around_close = '0' AND tbl_status_around_cpoint_id = '" + cpoint_id + "' AND tbl_status_around_cpoint_sub_id = '" + sub_cpoint + "'";
                                        cmd = new MySqlCommand(sql_check_straps, conn);
                                        reader.Close();
                                        reader = cmd.ExecuteReader();

                                        if (reader.Read())
                                        {
                                            btn_send.Enabled = true;
                                            sql_check_straps = "SELECT * FROM `tbl_income` JOIN `tbl_status_around` ON `tbl_income_around_id` = `tbl_status_around_id` JOIN `tbl_emp` ON `tbl_emp_id` = `tbl_income_emp_id` WHERE tbl_status_around_close = '0' AND tbl_status_around_cpoint_id = '" + cpoint_id + "' AND tbl_status_around_cpoint_sub_id = '" + sub_cpoint + "' AND tbl_income_bank IS NOT NULL AND tbl_income_status_backmaney ='1' ORDER BY tbl_income_id DESC ";
                                            reader.Close();
                                            reader = script.Select_SQL(sql_check_straps);
                                            if (reader.Read())
                                            {
                                                button2.Enabled  = true;
                                                btn_edit.Enabled = true;
                                            }
                                            else
                                            {
                                                button2.Enabled  = false;
                                                btn_edit.Enabled = false;
                                            }
                                        }
                                        else
                                        {
                                            button2.Enabled  = false;
                                            btn_send.Enabled = false;
                                            btn_edit.Enabled = false;
                                        }
                                        conn.Close();
                                        group_around.Visible = true;
                                        btn_around.Image     = Resources.error;
                                        btn_around.Text      = "ปิดกะ";
                                        aroundStatus         = false;

                                        if (around == 2)
                                        {
                                            button1.Enabled = true;
                                        }
                                        else
                                        {
                                            button1.Enabled = false;
                                        }
                                    }
                                }
                                else
                                {
                                    //lb_cpoint.Text = "ไม่พบข้อมูลด่าน";
                                    group_around.Visible = false;
                                    btn_around.Image     = Resources.success;
                                    btn_around.Text      = "เปิดกะ";
                                    aroundStatus         = true;

                                    btn_around.Enabled  = true;
                                    btn_bag.Enabled     = false;
                                    btn_send.Enabled    = false;
                                    btn_edit.Enabled    = false;
                                    btn_report.Enabled  = false;
                                    btn_refund.Enabled  = false;
                                    btn_memo.Enabled    = false;
                                    button1.Enabled     = false;
                                    button2.Enabled     = false;
                                    button3.Enabled     = false;
                                    btn_setting.Enabled = false;
                                }
                            }
                            catch
                            {
                            }
                            conn.Close();
                            // }
                            //button1.Enabled = false;
                        }
                        else
                        {
                            btn_around.Enabled  = false;
                            btn_bag.Enabled     = false;
                            btn_send.Enabled    = false;
                            btn_edit.Enabled    = false;
                            btn_report.Enabled  = true;
                            btn_refund.Enabled  = false;
                            btn_memo.Enabled    = false;
                            button1.Enabled     = true;
                            button2.Enabled     = false;
                            button3.Enabled     = false;
                            btn_setting.Enabled = false;
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("มีปัญหาการเชื่อมต่อฐานข้อมูล กรุุณาปิด/เปิดโปรแกรมใหม่ " + e.ToString(), "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //MessageBox.Show("Error:" + err.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }
            }
        }
コード例 #2
0
ファイル: ConfirmRefunForm.cs プロジェクト: kenji2511/TIS
        private void next()
        {
            ConnectDB       contxt = new ConnectDB();
            MySqlConnection conn   = new MySqlConnection();

            conn = new MySqlConnection(contxt.context());
            MySqlCommand comm  = conn.CreateCommand();
            bool         check = false;

            string sql_check_emp = "SELECT tbl_emp_id FROM tbl_emp WHERE tbl_emp_id = '" + txt_emp_id.Text + "' AND (tbl_emp_group_id=3 OR tbl_emp_group_id=7 OR tbl_emp_group_id=4 OR tbl_emp_group_id=10 OR tbl_emp_group_id=11 OR tbl_emp_group_id > 10)";

            comm = new MySqlCommand(sql_check_emp, conn);
            conn.Open();
            MySqlDataReader reader = comm.ExecuteReader();

            if (reader.Read())
            {
                check = true;
            }
            else
            {
                MessageBox.Show("รหัสไม่ถูกต้อง หรือไม่มีสิทธิ์ทำรายการ", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            conn.Close();

            if (check)
            {
                string sql_insert = "INSERT INTO tbl_refun (tbl_refun_job,tbl_refun_transaction,tbl_refun_amount,tbl_refun_emp,tbl_refun_note,tbl_refun_date) VALUES ('" + (refunForm.txt_job.SelectedItem as ComboboxItem).Value.ToString() + "','" + (refunForm.rdo_fine.Checked ? "ค่าปรับบัตรหาย" : "เงินทอน") + "','" + (refunForm.rdo_fine.Checked ? refunForm.txt_fine.Text : refunForm.txt_user.Text) + "','" + txt_emp_id.Text + "','" + refunForm.txt_note.Text + "',NOW())";
                conn.Open();
                comm.CommandText = sql_insert;
                if (comm.ExecuteNonQuery() > 0)
                {
                    check = true;
                }
                else
                {
                    check = false;
                }
                conn.Close();
                if (check)
                {
                    if (refunForm.rdo_fine.Checked == true)
                    {
                        if (refunForm.txt_fine.Text != "")
                        {
                            if (Int32.Parse(refunForm.txt_fine.Text) <= Int32.Parse(refunForm.fine))
                            {
                                conn.Open();
                                string sql = "UPDATE tbl_income SET tbl_income_fine = '" + (Int32.Parse(refunForm.fine) - Int32.Parse(refunForm.txt_fine.Text)) + "' WHERE tbl_income_id = '" + (refunForm.txt_job.SelectedItem as ComboboxItem).Value.ToString() + "'";
                                comm.CommandText = sql;
                                comm.ExecuteNonQuery();
                                MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "ผลลัพธ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                conn.Close();
                                mainForm.Enabled = true;
                                refunForm.Close();
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("ยอดเงินที่คืนผู้ใช้ทางมากกว่าเงินในระบบ " + (Int32.Parse(refunForm.txt_fine.Text) - Int32.Parse(refunForm.fine)) + " บาท", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }

                    if (refunForm.rdo_user.Checked == true)
                    {
                        if (refunForm.txt_user.Text != "")
                        {
                            if (Int32.Parse(refunForm.txt_user.Text) <= Int32.Parse(refunForm.user))
                            {
                                conn.Open();
                                string sql = "UPDATE tbl_income SET tbl_income_user = '******' WHERE tbl_income_id = '" + (refunForm.txt_job.SelectedItem as ComboboxItem).Value.ToString() + "'";
                                comm.CommandText = sql;
                                comm.ExecuteNonQuery();
                                MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "ผลลัพธ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                conn.Close();
                                refunForm.Close();
                                mainForm.Enabled = true;
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("ยอดเงินที่คืนผู้ใช้ทางมากกว่าเงินในระบบ " + (Int32.Parse(refunForm.txt_user.Text) - Int32.Parse(refunForm.user)) + " บาท", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
            }
        }