private void SyncADMINSSAuthority() { using (var SSEntities = new SmartShoppingEntities()) { try { //確定系統管理者擁有全部程式的權限 string ADMIN = "ADMIN"; //系統管理者ADMIN是否存在 var ADMINqry = (from E in SSEntities.SSUsers where E.Employee_ID == ADMIN select E).FirstOrDefault(); if (ADMINqry == null) { //新增系統管理者ADMIN SSUsers NewSSUsers = new SSUsers(); NewSSUsers.Employee_ID = ADMIN; NewSSUsers.EmployeeName = "系統管理員"; NewSSUsers.Password = ADMIN; SSEntities.SSUsers.Add(NewSSUsers); //更新資料 SSEntities.SaveChanges(); } //找出全部的程式 var qryPrograms = from P in SSEntities.SSPrograms select P.Program_ID; foreach (var P in qryPrograms) { //系統管理者的使用權限是否存在 var qry = (from A in SSEntities.SSAuthority where A.Employee_ID == ADMIN && A.Program_ID == P select A).FirstOrDefault(); if (qry == null) { //新增系統管理者的使用權限 SSAuthority NewAuthority = new SSAuthority(); NewAuthority.Employee_ID = ADMIN; NewAuthority.Program_ID = P; NewAuthority.Run = true; NewAuthority.Edit = true; SSEntities.SSAuthority.Add(NewAuthority); } } //更新資料 SSEntities.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void FromOrderToSmart() { using (SmartShoppingEntities db = new SmartShoppingEntities()) { db.Database.ExecuteSqlCommand("TRUNCATE TABLE [RoleSmart]"); var q = from r in db.View_RoleXProduct select r;//只從新增的開始讀?上次讀到幾要存起來 foreach (var item in q.ToList()) { //檢查RoleSmart資料表是否有此Role X Product的紀錄 var qry = (from P in db.RoleSmart where P.RoleID == item.Roles_ID && P.ProductID == item.Product_ID select P).FirstOrDefault(); if (qry == null) { //新增程式代碼記錄 var NewRS = new RoleSmart(); NewRS.RoleID = item.Roles_ID; NewRS.ProductID = item.Product_ID; NewRS.TimesPurchased = 1; NewRS.OrderBilling = item.Amount; //加入程式代碼 db.Entry(NewRS).State = EntityState.Added; db.SaveChanges(); } else { RoleSmart rs = db.RoleSmart.Find(item.Roles_ID, item.Product_ID); rs.TimesPurchased += 1; rs.OrderBilling += item.Amount; db.Entry(rs).State = EntityState.Modified; db.SaveChanges(); } } } }
private void btnOK_Click(object sender, EventArgs e) { //開始密碼變更,禁止關閉視窗 CanClose = false; //驗證程序 try { if (NewPasswordTextBox.Text == "") { MessageBox.Show("新密碼不可空白!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); NewPasswordTextBox.Focus(); return; } if (NewPasswordTextBox.Text != ConfirmPasswordTextBox.Text) { MessageBox.Show("新密碼與確認密碼不一致!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); NewPasswordTextBox.Focus(); return; } using (var SSEntities = new SmartShoppingEntities()) { var qry = (from U in SSEntities.SSUsers where U.Employee_ID == frmMain.FUserID && U.Password == OrignalPasswordTextBox.Text select U).FirstOrDefault(); if (qry == null) { MessageBox.Show("原來密碼錯誤!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); OrignalPasswordTextBox.Focus(); return; } //開始更新使用者的密碼 qry.Password = NewPasswordTextBox.Text; SSEntities.SaveChanges(); MessageBox.Show("密碼變更完成,下次登入請使用新密碼", "變更密碼", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } //完成密碼變更,允許關閉視窗 CanClose = true; }
//同步全部程式 private void SyncProgram() { using (var SSEntities = new SmartShoppingEntities()) { try { string ProgramName = ""; //取得目前的組件 Assembly thisAssembly = Assembly.GetExecutingAssembly(); //取得組件內所有類別型態 foreach (var t in thisAssembly.GetTypes()) { //如果父類別是繼承自Form的話 if (t.IsSubclassOf(typeof(Form))) { //列出該類別資訊 ProgramName = t.Name.ToString(); //檢查程式代碼資料表是否有此程式代碼的記錄 var qry = (from P in SSEntities.SSPrograms where P.ProgramName == ProgramName select P).FirstOrDefault(); int MaxID = SSEntities.SSPrograms.Max(i => i.Program_ID); if (qry == null) { //新增程式代碼記錄 var NewProgram = new SSPrograms(); NewProgram.Program_ID = MaxID + 1; NewProgram.ProgramName = ProgramName; //加入程式代碼 SSEntities.SSPrograms.Add(NewProgram); //更新資料 SSEntities.SaveChanges(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void button3_Click(object sender, EventArgs e) { AdHTML = htmlEditorControl1.InnerHtml; //using (EditHtmlForm dialog = new EditHtmlForm()) //{ // dialog.HTML = this.DocumentHtml; // dialog.ReadOnly = true; // dialog.SetCaption(HTML_TITLE_VIEW); // DefineDialogProperties(dialog); // dialog.ShowDialog(this.ParentForm); //} //寫進資料庫 using (SmartShoppingEntities db = new SmartShoppingEntities()) { //新增 if (NewAd) { Promotions promotion = new Promotions(); promotion.AdHtml = AdHTML; promotion.PromotionName = this.textBoxTitle.Text; db.Entry(promotion).State = EntityState.Added; } else { //修改 Promotions promotion = db.Promotions.Find(AdID); promotion.AdHtml = AdHTML; promotion.PromotionName = this.textBoxTitle.Text; db.Entry(promotion).State = EntityState.Modified; } try { db.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } LoadAdLabel(); MessageBox.Show("儲存成功"); }
//同步全部使用者權限(系統管理者擁有全部程式的權限,其他使用者至少要有更改自己密碼的權限) private void SyncBaceSSAuthority() { using (var SSEntities = new SmartShoppingEntities()) { try { //其他使用者至少要有更改自己密碼的權限 string EmployeeID; //找出全部的使用者 var qrysUsers = from E in SSEntities.SSUsers select E.Employee_ID; foreach (var U in qrysUsers) { EmployeeID = (string)U; var qry = (from A in SSEntities.SSAuthority where A.Employee_ID == EmployeeID select A).FirstOrDefault(); if (qry == null) { var ProgramUserPassword = (SSEntities.SSPrograms.Where(i => i.ProgramName == "frmUserPassword")).FirstOrDefault(); //新增使用權限記錄 SSAuthority NewAuthority = new SSAuthority(); NewAuthority.Employee_ID = EmployeeID; NewAuthority.Program_ID = ProgramUserPassword.Program_ID; NewAuthority.Run = true; NewAuthority.Edit = true; SSEntities.SSAuthority.Add(NewAuthority); } } //更新資料 SSEntities.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }