コード例 #1
0
ファイル: Memer_Form.cs プロジェクト: iphone100s/easyERP
        //新增
        private void IInsertMember_button_Click(object sender, EventArgs e)
        {
            string memberAccount = this.memberAccount_textbox.Text.Trim();
            string memberName    = this.memberName_textBox.Text.Trim();
            string password      = this.password_textBox.Text.Trim();
            string memberID      = this.memberID_textBox.Text.Trim();


            //下拉式選單
            KeyValuePair <string, string> kvp = (KeyValuePair <string, string>)status_comboBox.SelectedItem;
            string key   = kvp.Key.ToString();
            string Value = kvp.Value.ToString();

            //下拉式選單
            KeyValuePair <string, string> Membererror = (KeyValuePair <string, string>)error_comboBox.SelectedItem;
            string keyError   = Membererror.Key.ToString();
            string ValueError = Membererror.Value.ToString();

            string selectID = "select memberID from Member where memberID='" + memberID + "' ";
            //string selectID = "select memberID from Member";
            SqlHelp sqlhelper = new SqlHelp();

            DataSet ds = sqlhelper.SqlServerRecordCount2(selectID); // 返回符合的結果數量



            using (SqlConnection con = new SqlConnection(_connecString))
            {
                con.Open();

                SqlCommand cmd = new SqlCommand();
                {
                    try
                    {
                        if (memberAccount.Equals("") || password.Equals("") || memberName.Equals("") || memberID.Equals(""))
                        {
                            MessageBox.Show("請勿空白帳號,姓名,密碼,員工ID!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string ReturnPermission = ds.Tables["Member"].Rows[0]["memberID"].ToString();
                            if (ReturnPermission.Equals(memberID))
                            {
                                MessageBox.Show("請勿重複員工ID!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                return;
                            }
                        }
                        else
                        {
                            cmd = new SqlCommand("insert into Member(memberAccount, password, memberName, permission,permissionName, memberError,memberErrorName,memberID) values('" + memberAccount + "','" + password + "','" + memberName + "','" + Value + "','" + key + "'," + ValueError + ",'" + keyError + "','" + memberID + "') ", con);
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("資料儲存成功!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            cmd = new SqlCommand(" select memberID,memberAccount, password, memberName, permissionName, memberErrorName from Member where memberID ='" + memberID + "' ", con);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }

                //SqlCommand cmd1 = new SqlCommand();
                //{

                //    //全部搜尋
                //    //cmd1 = new SqlCommand(" select * from Member ", con);

                //    //單筆搜尋
                //    cmd1 = new SqlCommand(" select memberID,memberAccount, password, memberName, permissionName from Member where memberAccount ='" + memberAccount + "' ", con);

                //}

                DataTable      dt1 = new DataTable();
                SqlDataAdapter da1 = new SqlDataAdapter(cmd);
                da1.Fill(dt1);

                select_dataGridView.DataSource = dt1;
            }
        }
コード例 #2
0
        private void Login_button_Click(object sender, EventArgs e)
        {
            string username = this.userTextBox.Text;
            string password = this.passwordTextBox.Text;

            try
            {
                if (username.Equals("") || password.Equals(""))
                {
                    MessageBox.Show("請勿空白帳號密碼!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    string selectAccount = "select * from Member where memberAccount='" + username + "'and password='******'"; //正式用資料庫

                    SqlHelp sqlhelper = new SqlHelp();


                    DataSet ds = sqlhelper.SqlServerRecordCount2(selectAccount); // 返回符合的結果數量

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        string ReturnPermission  = ds.Tables["Member"].Rows[0]["permission"].ToString(); //.Rows[0] 抓一排 如果0改成1 就是往下抓一排
                        int    ReturnNemberError = (int)ds.Tables["Member"].Rows[0]["memberError"];      //.Rows[0] 抓一排 如果0改成1 就是往下抓一排

                        //string sqlname = ds.Tables["Member"].Rows[0]["memberName"].ToString();
                        if (ReturnNemberError > 2)
                        {
                            MessageBox.Show("密碼已被鎖定!! 請洽管理員", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return;
                        }
                        if (ReturnPermission.Equals("A") || ReturnPermission.Equals("B"))
                        {
                            ReturnPermission = ds.Tables["Member"].Rows[0]["memberName"].ToString().Trim();


                            string updateDeleteMemberError = "UPDATE Member SET memberError = 0  WHERE memberAccount ='" + username + "' ; "; //正式用資料庫
                            sqlhelper.SqlServerRecordCount2(updateDeleteMemberError);


                            MessageBox.Show(ReturnPermission + " 歡迎您登入,請按確定登入系統", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            //跳轉道主頁面
                            Second_Form view = new Second_Form();

                            view.Show(); //顯示新頁面
                            this.Hide(); //隱藏當前頁面
                                         //this.Close();//關閉視窗
                        }
                        if (ReturnPermission.Equals("C"))
                        {
                            string updateDeleteMemberError = "UPDATE Member SET memberError = 0  WHERE memberAccount ='" + username + "' ; "; //正式用資料庫
                            sqlhelper.SqlServerRecordCount2(updateDeleteMemberError);

                            ReturnPermission = ds.Tables["Member"].Rows[0]["memberName"].ToString().Trim();

                            MessageBox.Show(ReturnPermission + " 歡迎您登入,請按確定登入系統", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            //跳轉道主頁面
                            Second_Form view = new Second_Form();
                            view.Show();                        //顯示新頁面
                            this.Hide();                        //隱藏當前頁面
                            view.member_button.Enabled = false; //讓button反灰(屬性的modifiers要改成public)
                                                                //this.Close();//關閉視窗
                                                                //view.select_button.Visible = false;  //讓button不見
                        }
                    }
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        string  selectMemberError = "select memberAccount,memberError from Member where memberAccount='" + username + "' ; "; //正式用資料庫
                        DataSet selectError       = sqlhelper.SqlServerRecordCount2(selectMemberError);
                        if (selectError.Tables["Member"].Rows.Count > 0)
                        {
                            int ReturnNemberError = (int)selectError.Tables["Member"].Rows[0]["memberError"]; //.Rows[0] 抓一排 如果0改成1 就是往下抓一排

                            if (ReturnNemberError < 3)
                            {
                                string updateAddMemberError = "UPDATE Member SET memberError = memberError + 1 WHERE memberAccount ='" + username + "' ; "; //正式用資料庫
                                sqlhelper.SqlServerRecordCount2(updateAddMemberError);
                                MessageBox.Show("密碼錯誤喔!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            }
                            if (ReturnNemberError == 3)
                            {
                                string updateAddMemberError = "UPDATE Member SET memberErrorName = '已鎖定' WHERE memberAccount ='" + username + "' ; "; //正式用資料庫
                                sqlhelper.SqlServerRecordCount2(updateAddMemberError);
                                MessageBox.Show("帳號已鎖定!!請洽管理員", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            }
                        }
                        else
                        {
                            MessageBox.Show("帳號或密碼錯誤喔!!", "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("系統有問題,請洽管理員!!!" + ex.Message, "提示訊息", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }