コード例 #1
0
        /// <summary>
        /// 更新資料庫資料
        /// </summary>
        private void RunUpdateData(string PageName)
        {
            ArrayList arrList = new ArrayList();

            My.MyDatabase MyDb = new My.MyDatabase();

            switch (PageName)
            {
            case "tabPage1":    //一般使用者
                SIS.DBClass.DBClassUserInfo DbUI = new SIS.DBClass.DBClassUserInfo();

                string UserId         = this.txtUserId.Text;
                string CNAME          = this.txtCNAME.Text;
                string ENAME          = this.txtENAME.Text;
                string Sex            = this.cboSex.Text;
                string Birthday       = this.dtpBirthday.Value.ToString("yyyy年MM月dd日");
                string BoolType       = this.cboBooldType.Text;
                string ID             = this.mtbID.Text;
                string PresentAddress = this.txtPresentAddress.Text;
                string Phone          = mtbPhone.Text;

                arrList.Clear();
                arrList.Insert(0, UserId);
                arrList.Insert(1, CNAME);
                arrList.Insert(2, ENAME);
                arrList.Insert(3, Sex);
                arrList.Insert(4, Birthday);
                arrList.Insert(5, BoolType);
                arrList.Insert(6, ID);
                arrList.Insert(7, PresentAddress);
                arrList.Insert(8, Phone);


                //資料存在才進行更新動作
                if (MyDb.AuthPK(UserId, "UserId", "UserInfo") == true)
                {
                    if (DbUI.Update(arrList))
                    {
                        MessageBox.Show("更新" + UserId + "-" + CNAME +
                                        "一般使用者資料成功", "更新人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue1();
                    }
                    else
                    {
                        MessageBox.Show("更新" + UserId + "-" + CNAME +
                                        "一般使用者資料失敗", "更新人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫不存在 " + UserId + "-" + CNAME +
                                    " 人員資料!!(無法更新)", "資料更新");
                }

                break;

            case "tabPage2":    //進銷存管理者
                SIS.DBClass.DBClassManagementInfo DbMI = new SIS.DBClass.DBClassManagementInfo();

                string UserId2         = this.txtUserId2.Text;
                string CNAME2          = this.txtCNAME2.Text;
                string ENAME2          = this.txtENAME2.Text;
                string Sex2            = this.cboSex2.Text;
                string Birthday2       = this.dtpBirthday2.Value.ToString("yyyy年MM月dd日");
                string BoolType2       = this.cboBooldType2.Text;
                string ID2             = this.mtbID2.Text;
                string PresentAddress2 = this.txtPresentAddress2.Text;
                string Phone2          = mtbPhone2.Text;
                string Title           = cboTitle.Text;

                arrList.Clear();
                arrList.Insert(0, UserId2);
                arrList.Insert(1, CNAME2);
                arrList.Insert(2, ENAME2);
                arrList.Insert(3, Sex2);
                arrList.Insert(4, Birthday2);
                arrList.Insert(5, BoolType2);
                arrList.Insert(6, ID2);
                arrList.Insert(7, PresentAddress2);
                arrList.Insert(8, Phone2);
                arrList.Insert(9, Title);


                if (MyDb.AuthPK(UserId2, "UserId", "ManagementInfo") == true)
                {
                    if (DbMI.Update(arrList))
                    {
                        MessageBox.Show("更新" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料成功", "更新人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue2();
                    }
                    else
                    {
                        MessageBox.Show("更新" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料失敗", "更新人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫不存在 " + UserId2 + "-" + CNAME2 +
                                    " 人員資料!!(無法更新)", "資料更新");
                }

                break;
            }
        }
コード例 #2
0
        /// <summary>
        /// 刪除資料庫資料
        /// </summary>
        private void RunDeleteData(string PageName)
        {
            ArrayList arrList = new ArrayList();

            My.MyDatabase MyDb = new My.MyDatabase();

            switch (PageName)
            {
            case "tabPage1":    //一般使用者
                SIS.DBClass.DBClassUserInfo DbUI = new SIS.DBClass.DBClassUserInfo();

                string UserId = this.txtUserId.Text;
                string CNAME  = this.txtCNAME.Text;



                //資料存在才進行更新動作
                if (MyDb.AuthPK(UserId, "UserId", "UserInfo") == true)
                {
                    if (DbUI.DeleteOneData(UserId))
                    {
                        MessageBox.Show("刪除" + UserId + "-" + CNAME +
                                        "一般使用者資料成功", "刪除人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue1();
                    }
                    else
                    {
                        MessageBox.Show("刪除" + UserId + "-" + CNAME +
                                        "一般使用者資料失敗", "刪除人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫不存在 " + UserId + "-" + CNAME +
                                    " 人員資料!!(無法刪除)", "資料刪除");
                }

                break;

            case "tabPage2":    //進銷存管理者
                SIS.DBClass.DBClassManagementInfo DbMI = new SIS.DBClass.DBClassManagementInfo();

                string UserId2 = this.txtUserId2.Text;
                string CNAME2  = this.txtCNAME2.Text;


                if (MyDb.AuthPK(UserId2, "UserId", "ManagementInfo") == true)
                {
                    if (DbMI.DeleteOneData(UserId2))
                    {
                        MessageBox.Show("刪除" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料成功", "刪除人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue2();
                    }
                    else
                    {
                        MessageBox.Show("刪除" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料失敗", "刪除人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫不存在 " + UserId2 + "-" + CNAME2 +
                                    " 人員資料!!(無法刪除)", "資料刪除");
                }

                break;
            }
        }
コード例 #3
0
        /// <summary>
        /// 將資料寫入資料庫中
        /// </summary>
        private void RunInsertData(string PageName)
        {
            ArrayList arrList = new ArrayList();

            My.MyDatabase MyDb = new My.MyDatabase();

            switch (PageName)
            {
            case "tabPage1":    //一般使用者
                SIS.DBClass.DBClassUserInfo DbUI = new SIS.DBClass.DBClassUserInfo();

                string UserId         = this.txtUserId.Text;
                string CNAME          = this.txtCNAME.Text;
                string ENAME          = this.txtENAME.Text;
                string Sex            = this.cboSex.Text;
                string Birthday       = this.dtpBirthday.Value.ToString("yyyy年MM月dd日");
                string BoolType       = this.cboBooldType.Text;
                string ID             = this.mtbID.Text;
                string PresentAddress = this.txtPresentAddress.Text;
                string Phone          = mtbPhone.Text;

                arrList.Clear();
                arrList.Insert(0, UserId);
                arrList.Insert(1, CNAME);
                arrList.Insert(2, ENAME);
                arrList.Insert(3, Sex);
                arrList.Insert(4, Birthday);
                arrList.Insert(5, BoolType);
                arrList.Insert(6, ID);
                arrList.Insert(7, PresentAddress);
                arrList.Insert(8, Phone);



                if (MyDb.AuthPK(UserId, "UserId", "UserInfo") == false)
                {
                    if (DbUI.InsertData(arrList))
                    {
                        MessageBox.Show("新增" + UserId + "-" + CNAME +
                                        "一般使用者資料成功", "新增人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue1();
                        if (InsertNewLoginAccount(UserId, "Users"))
                        {
                            MessageBox.Show("帳號:[" + UserId + "]建立成功,預設密碼為[12345],登入系統後請記得變更。", "建立登入系統帳號成功");
                        }
                    }
                    else
                    {
                        MessageBox.Show("新增" + UserId + "-" + CNAME +
                                        "一般使用者資料失敗", "新增人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫已存在 " + UserId + "-" + CNAME +
                                    " 人員資料!!(資料重複)", "資料新增");
                }

                break;

            case "tabPage2":    //進銷存管理者
                SIS.DBClass.DBClassManagementInfo DbMI = new SIS.DBClass.DBClassManagementInfo();

                string UserId2         = this.txtUserId2.Text;
                string CNAME2          = this.txtCNAME2.Text;
                string ENAME2          = this.txtENAME2.Text;
                string Sex2            = this.cboSex2.Text;
                string Birthday2       = this.dtpBirthday2.Value.ToString("yyyy年MM月dd日");
                string BoolType2       = this.cboBooldType2.Text;
                string ID2             = this.mtbID2.Text;
                string PresentAddress2 = this.txtPresentAddress2.Text;
                string Phone2          = mtbPhone2.Text;
                string Title           = cboTitle.Text;

                arrList.Clear();
                arrList.Insert(0, UserId2);
                arrList.Insert(1, CNAME2);
                arrList.Insert(2, ENAME2);
                arrList.Insert(3, Sex2);
                arrList.Insert(4, Birthday2);
                arrList.Insert(5, BoolType2);
                arrList.Insert(6, ID2);
                arrList.Insert(7, PresentAddress2);
                arrList.Insert(8, Phone2);
                arrList.Insert(9, Title);


                if (MyDb.AuthPK(UserId2, "UserId", "ManagementInfo") == false)
                {
                    if (DbMI.InsertData(arrList))
                    {
                        MessageBox.Show("新增" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料成功", "新增人員資料", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultValue2();
                        if (InsertNewLoginAccount(UserId2, "Management"))
                        {
                            MessageBox.Show("帳號:[" + UserId2 + "]建立成功,預設密碼為[12345],登入系統後請記得變更。", "建立登入系統帳號成功");
                        }
                    }
                    else
                    {
                        MessageBox.Show("新增" + UserId2 + "-" + CNAME2 +
                                        "進銷存管理者資料失敗", "新增人員資料", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("對不起,資料庫已存在 " + UserId2 + "-" + CNAME2 +
                                    " 人員資料!!(資料重複)", "資料新增");
                }

                break;
            }
        }