예제 #1
0
 private void SyncUserAuthority()
 {
     using (var context = new XINEntities())
     {
         string EmployeeNo, ProgramID;
         try
         {
             //找出所有的程式代碼記錄
             var qryPrograms = from P in context.Programs
                               select P.ProgramID;
             //找出所有的使用者代碼記錄
             var qrysUsers = from E in context.XINUsers
                             select E.EmployeeNo;
             foreach (var P in qryPrograms)
             {
                 ProgramID = (string)P;
                 foreach (var U in qrysUsers)
                 {
                     EmployeeNo = (string)U;
                     var qry = (from A in context.UserAuthority
                                where A.EmployeeNo == EmployeeNo &&
                                A.ProgramID == ProgramID
                                select A).FirstOrDefault();
                     if (qry == null)
                     {
                         //新增使用權限記錄
                         UserAuthority NewAuthority = new UserAuthority();
                         NewAuthority.EmployeeNo = EmployeeNo;
                         NewAuthority.ProgramID  = ProgramID;
                         NewAuthority.Run        = true;
                         NewAuthority.Append     = true;
                         NewAuthority.Edit       = true;
                         NewAuthority.Report     = true;
                         context.AddObject("UserAuthority", NewAuthority);
                     }
                 }
             }
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
     }
 }
예제 #2
0
 private void SyncAdminUsers()
 {
     using (var context = new XINEntities())
     {
         //檢查使用者代碼資料表是否有ADMIN的使用者
         var qry = (from E in context.XINUsers
                    where E.EmployeeNo == "ADMIN"
                    select E.EmployeeNo).FirstOrDefault();
         if (qry == null)
         {
             //新增ADMIN使用者
             XINUsers NewXINUsers = new XINUsers();
             NewXINUsers.EmployeeNo   = "ADMIN";
             NewXINUsers.EmployeeName = "系統管理員";
             NewXINUsers.PasswordCode = "ADMIN";
             //加入ADMIN使用者
             context.AddObject("XINUsers", NewXINUsers);
             //更新資料
             context.SaveChanges();
         }
     }
 }
예제 #3
0
 private void SyncProgramID()
 {
     using (var context = new XINEntities())
     {
         try
         {
             string sName;
             string ProgramID, ProgramName;
             //從MenuStrip1控制項集合找出每一個控制項
             foreach (var tsmi in MenuStrip1.Items)
             {
                 if (!(tsmi is ToolStripItem))
                 {
                     continue;
                 }
                 //找出MenuStrip1.Items的子控制項
                 foreach (var SubItem in
                          ((ToolStripMenuItem)(tsmi)).DropDownItems)
                 {
                     //判斷找出的控制項是否為ToolStripMenuItem類別
                     if (!(SubItem is ToolStripMenuItem))
                     {
                         continue;
                     }
                     sName = ((ToolStripMenuItem)SubItem).Name.Substring(2, 3);
                     if ((sName == "Dtn") || (sName == "Txn") ||
                         (sName == "Rpt") || (sName == "Qry"))
                     {
                         //程式代碼
                         ProgramID = ((ToolStripMenuItem)SubItem).Name
                                     .Substring(2);
                         //程式名稱
                         ProgramName = ((ToolStripMenuItem)SubItem).Text;
                         //檢查程式代碼資料表是否有此程式代碼的記錄
                         var qry = (from P in context.Programs
                                    where P.ProgramID == ProgramID
                                    select P).FirstOrDefault();
                         if (qry == null)
                         {
                             //新增程式代碼記錄
                             Programs NewProgram = new Programs();
                             NewProgram.ProgramID   = ProgramID;
                             NewProgram.ProgramName = ProgramName;
                             //加入程式代碼
                             context.AddObject("Programs", NewProgram);
                             //更新資料
                             //context.SaveChanges();
                         }
                         else
                         {
                             //修改程式代碼記錄
                             qry.ProgramName = ProgramName;
                         }
                         //更新資料
                         context.SaveChanges();
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "啟動錯誤", MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
     }
 }