public Frm_BulletinPublish(Frm_HomePage form)//傳入上層傳來的 this 參數 { InitializeComponent(); hp = form; this.CenterToScreen(); string[] categoryItems = new string[] { "[重要公告]", "[活動通知]", "[系統維護]" }; this.cbbCategory.Items.AddRange(categoryItems); this.cbbCategory1.Items.AddRange(categoryItems); LoadDgv(); this.dataGridView1.SelectionChanged += DataGridView1_SelectionChanged; }
private void btnWuChaRevise_Submit_Click(object sender, EventArgs e) { int ReviseNumber = int.Parse(this.comWuCha_To10.Text); try { string strr = Settings.Default.MyHR; using (SqlConnection conn = new SqlConnection(strr)) { SqlCommand command = new SqlCommand(); command.Connection = conn; conn.Open(); if (ReviseNumber == 0) { command.CommandText = $"Update [dbo].[OrderStoreDetail] set [ItemQuantity] ={ReviseNumber} where[WuChaOrderNumber] = {WuCha_ReceiveID} and[ItemID] = {ChangToWuChaItemID(WuCha_ReceiveItem)}"; command.ExecuteNonQuery(); command.CommandText = $"Delete from [dbo].[OrderStoreDetail] where[ItemQuantity] = {ReviseNumber}"; command.ExecuteNonQuery(); } else { command.CommandText = $"Update [dbo].[OrderStoreDetail] set [ItemQuantity] ={ReviseNumber} where[WuChaOrderNumber] = {WuCha_ReceiveID} and[ItemID] = {ChangToWuChaItemID(WuCha_ReceiveItem)}"; command.ExecuteNonQuery(); } MessageBox.Show("訂單已修改"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Frm_HomePage ower = (Frm_HomePage)this.Owner; ower.RefreshWuCha(); this.Close(); //var q = (this.hrEntities.OrderStoreDetails.AsEnumerable().Where(o => o.WuChaOrderNumber == int.Parse(WuCha_ReceiveID) && o.ItemID == ChangToWuChaItemID(WuCha_ReceiveItem))).FirstOrDefault(); //if(q != null) //{ // q.ItemQuantity = 1; // this.hrEntities.SaveChanges(); //} }
int count = 1;//計算登入次數 private void OK_Click(object sender, EventArgs e) { try { int UserID = int.Parse(this.UsernameTextBox.Text); string password = this.PasswordTextBox.Text; string connstring = Settings.Default.MyHR; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = connstring; SqlCommand command = new SqlCommand(); command.Connection = conn; command.CommandText = $"select AccountEnable,EmployeeName from [User] where EmployeeID=@UserID and PassWord=@Password"; command.Parameters.Add("@UserID", SqlDbType.NVarChar, 16).Value = UserID; command.Parameters.Add("@Password", SqlDbType.NVarChar, 40).Value = password; conn.Open(); SqlDataReader dataReader = command.ExecuteReader(); int x = 0; MyHREntities hr = new MyHREntities(); dataReader.Read(); if (dataReader.HasRows) { x = int.Parse(dataReader[0].ToString()); if (x == 1) { MessageBox.Show($"登入成功,歡迎~{dataReader[1]},祝您有個美好的一天"); Frm_HomePage hp = new Frm_HomePage(); hp.UserID = UserID;//傳 UserID 到 Hompage this.Visible = false; hp.ShowDialog(); this.Dispose(); this.Close(); } else { MessageBox.Show("帳號未啟用[AccountEnable],請通知管理員"); } } else { MessageBox.Show("登入失敗,請確認帳號密碼是否輸入錯誤"); count++; if (count > 3) { MessageBox.Show("帳號已關閉,請聯絡管理員!"); var q = from p in hr.Users where p.EmployeeID == UserID select p; foreach (var i in q) { i.AccountEnable = 0; } hr.SaveChanges(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }