Esempio n. 1
0
        //編輯(修改): 1.修改AccountStatus 2.重設密碼
        async private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //e.ColumnIndex 選在 '編輯' 欄位,e.RowIndex 不等於 header 裡的 '編輯'(不然按到 header 會出錯)
            if (e.ColumnIndex == 0 && e.RowIndex != -1)
            {
                BuyerAccountForm_Update.CellEmpID = (string)this.dataGridView1.Rows[e.RowIndex].Cells["員工帳號"].Value;
                Common.ContainerForm.NextForm(new BuyerAccountForm_Update());
            }
            //e.ColumnIndex 選在 '重設密碼' 欄位
            if (e.ColumnIndex == 1 && e.RowIndex != -1)
            {
                string myEmpID       = (string)this.dataGridView1.Rows[e.RowIndex].Cells["員工帳號"].Value;
                string myEmpEmail    = (string)this.dataGridView1.Rows[e.RowIndex].Cells["電子信箱"].Value;
                string accountStates = (string)this.dataGridView1.Rows[e.RowIndex].Cells["啟用狀態"].Value;
                Guid   salt          = Guid.NewGuid();
                string password      = Util.BuildAuthToken();
                string hashPassword  = Util.GetHash(password + salt.ToString());

                //int buyerOID = dao.CreateBuyer(id, hashPassword, salt.ToString(), accountStatus, createDate);
                //TODO 非同步
                await Task.Run(() =>
                {
                    //TODO ***信箱寫死 要用可換成變數 myEmpEmail
                    CreateBuyerService.SendEmailToEmp(password, "*****@*****.**", out string BSendLetterState);
                    //重設密碼 更新寄信時間
                    string bSendLetterDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                    PurchasingOrder.BuyerDao.updateBuyerbSendLetterDate(bSendLetterDate, myEmpID);
                });

                MessageBox.Show("郵件寄送成功!");
            }
        }
Esempio n. 2
0
 static void Test()
 {
     var context = CreateBuyerServiceTestContext.Setup();
     var sut     = new CreateBuyerService(
         null,
         context.UsersRepositoryMock.Object,
         context.PasswordServiceMock.Object,
         context.RegistrationServiceMock.Object);
 }
        public static void Constructor_NullRegistrationService_ThrowsException()
        {
            var context = CreateBuyerServiceTestContext.Setup();

            Assert.Throws <ArgumentNullException>(() => _ = new CreateBuyerService(
                                                      context.ApplicationUserValidatorMock.Object,
                                                      context.UsersRepositoryMock.Object,
                                                      context.PasswordServiceMock.Object,
                                                      null));
        }
        //1. 新增到 Buyer 資料表
        async private void btnInsert_Confirm_Click(object sender, EventArgs e)
        {
            //TODO salt和pwd
            //string salt = Convert.ToString(Guid.NewGuid());
            //string password = Util.BuildAuthToken();
            //string hashPassword = Util.GetHash(password + salt.ToString());
            string bSendLetterState = "N";
            string BSendLetterState = "S";

            try
            {
                //Insert
                string typeIntxtEmpID = txtEmpID.Text;
                string modifiedDate   = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                //TODO 非同步寄信狀態
                //非同步
                string bSendLetterDate = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                bSendLetterState = BSendLetterState;
                string password = "";
                PurchasingOrder.BuyerDao.insertEmpToBuyer(typeIntxtEmpID, accStatus, modifiedDate, bSendLetterState, bSendLetterDate, ref password);
                Common.ContainerForm.NextForm(new BuyerAccountForm());
                bool mailResult = false;
                await Task.Run(() =>
                {
                    mailResult = CreateBuyerService.SendEmailToEmp(password, "*****@*****.**", out BSendLetterState);
                    PurchasingOrder.BuyerDao.updateBuyerBsendLetterStatus(typeIntxtEmpID, "Y");
                });

                if (mailResult)
                {
                    MessageBox.Show("發送密碼成功!");
                }
                else
                {
                    MessageBox.Show("發送密碼失敗!");
                }
            }
            catch (Exception)
            {
                this.txtEmpID.Select();
                this.txtEmpID.Text = "";
                MessageBox.Show("新增失敗!此帳號已存在或有誤!", "失敗", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            MessageBox.Show("新增成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }