附錄\E. Scheduling文件說明\Scheduling應用

.、定期將AD資訊更新至系統表中

需要寫程式做一個ServerMethod,來實現排程。

註:請先檢查系統表的欄位長度是否夠長。

 

1. ServerMethod的範例如下:

public object ADTEST(object[] param)

        {

            //取得ADUsersADGroup

            ADClass.ADPath = "LDAP://" + ServerConfig.DomainPath;

            ADClass.ADUser = ServerConfig.DomainUser;

            ADClass.ADPassword = ServerConfig.DomainPassword;

            List<ADUser> lstUser = new List<ADUser>();

            List<ADGroup> lstGroup = new List<ADGroup>();

            try

            {

                lstUser = ADClass.GetADAllUser();

                lstGroup = ADClass.GetADUserForGroup();

            }

            catch

            {

                return new object[] { 1, "Please Setup \"EEPNetServer/Login Manger\" Frist" };

            }

            ArrayList Userlist = new ArrayList();

            Userlist.AddRange(lstUser.ToArray());

            ArrayList Grouplist = new ArrayList();

            Grouplist.AddRange(lstGroup.ToArray());

            //創建連接

            IDbConnection connection = (IDbConnection)AllocateConnection(GetClientInfo(ClientInfoType.LoginDB).ToString());

            if (connection.State != ConnectionState.Open)

            {

                connection.Open();

            }

            //開始transaction

            IDbTransaction transaction = connection.BeginTransaction();

            try

            {

                //ADUser,新增前先刪除AD舊有資料

                string UserDeleteSql = "delete from USERS where MSAD='Y'";

                this.ExecuteSql(UserDeleteSql, connection, transaction);

                ADUser ADUse = new ADUser();

                for (int i = 0; i < Userlist.Count; i++)

                {

                    ADUse = (ADUser)Userlist[i];

                    string UserID = ADUse.ID.ToString();

                    string USERNAME = ADUse.Name.ToString();

                    string DESCRIPTION = ADUse.Description.ToString();

                    string EMAIL = ADUse.Email.ToString();

                    //ADUsers資訊insertUsers

                    string UserinsertSql = "insert into USERS (USERID,USERNAME,DESCRIPTION,EMAIL,MSAD) " + "values('" + UserID + "','" + USERNAME + "','" + DESCRIPTION + "','" + EMAIL + "','Y')";

                    this.ExecuteSql(UserinsertSql, connection, transaction);

                }

                //ADGroup,新增前先刪除AD舊有資料

                string GroupdeleteSql = "delete from GROUPS where MSAD='Y'";

                this.ExecuteSql(GroupdeleteSql, connection, transaction);

                string UserGroupdeleteSql = "delete from USERGROUPS";

                this.ExecuteSql(UserGroupdeleteSql, connection, transaction);

                ADGroup ADGrou = new ADGroup();

                for (int i = 0; i < Grouplist.Count; i++)

                {

                    ADGrou = (ADGroup)Grouplist[i];

                    string GROUPID = ADGrou.ID.ToString();

                    string DESCRIPTION = ADGrou.Description.ToString();

                    string USERID = "";

                    //Group裡有User時才做新增動作

                    if (ADGrou.Users.Count != 0)

                    {

                        //ADGroups資訊insertGroups

                        string GroupinsertSql = "insert into GROUPS (GroupID,DESCRIPTION,MSAD) values('" + GROUPID + "','" + DESCRIPTION + "','Y')";

                        this.ExecuteSql(GroupinsertSql, connection, transaction);

                        //AD資訊insertUserGroups

                        for (int j = 0; j < ADGrou.Users.Count; j++)

                        {

                            USERID = ADGrou.Users[j].ToString();

                            string UserGroupinsertSql = "insert into USERGROUPS (USERID,GROUPID) values('" + USERID + "','" + GROUPID + "')";

                            this.ExecuteSql(UserGroupinsertSql, connection, transaction);

                        }

                    }

                }

                transaction.Commit();

                return new object[] { 0, true };

            }

            catch

            {

                transaction.Rollback();

                return new object[] { 1, "表中有資料重複或者發生錯誤!" };

            }

            finally

            {

                ReleaseConnection(GetClientInfo(ClientInfoType.LoginDB).ToString(), connection);

            }           

        }

 

2. 請將此MethodName加入至ServiceManager元件中做設定,並建置專案。

3. 設定Scheduling:本例是以每個月5號早上八點執行,設定如下。

 

 

4. 設定好並保存後,把右下角功能列中的Scheduling按右鍵,選擇【Active】即完成。

 

.、自動起單

需要寫程式做一個ServerMethod,來實現排程。

 

1. ServerMethod的範例如下:

public object StartFlowStep(object[] objPatam)

        {

            string TestID = "0000001";

            string USERID = "003";//申請者的 ID

            string USERNAME = "Rena";//申請者姓名

 

            DbConnectionSet.DbConnection DC = Srvtools.DbConnectionSet.GetDbConn(GetClientInfo(ClientInfoType.LoginDB).ToString());

            string connstring = DC.ConnectionString;

            SqlConnection sqlconn = new System.Data.SqlClient.SqlConnection(connstring);

            //填入表單資料

            SqlCommand sqlcmd = new SqlCommand(" Insert into TestMaster (TestID,TestName,TestMark) values (@TestID,@TestName,@TestMark)", sqlconn);

            sqlcmd.Parameters.AddWithValue("@TestID", TestID);

            sqlcmd.Parameters.AddWithValue("@TestName", USERNAME);

            sqlcmd.Parameters.AddWithValue("@TestMark", USERID);

 

            sqlconn.Open();

            sqlcmd.ExecuteNonQuery();

            sqlconn.Close();

 

            EEPRemoteModule module = new EEPRemoteModule();

            object[] clientInfo = new object[] { this.ClientInfo[0], -1, -1, string.Empty };

 

            string UserId = ((object[])clientInfo[0])[1].ToString(); //先記錄原登入者

 

            UserId = UserId.ToLower(); //系統用小寫比對

            USERID = USERID.ToLower();

            SrvGL.LogUser(USERID, USERNAME, "WFPlus", 1); //登錄

            ((object[])clientInfo[0])[1] = USERID; // 強制更改 ClientInfo USERID 為申請者的 ID

 

            object[] ret = module.CallFLMethod(clientInfo, "Submit", new object[]{null, new object[]{

                    EEPRegistry.Server.ToString() + "\\Workflow\\FL\\Test.xoml",//流程文件名字,包含完整路徑。

                    "",//空白即可,系統使用

                    0,//是否為重要申請

                    0,//是否為緊急申請

                    "", //提交意見說明

                    "R01",//申請者的RoleID

                    "sCustomers.Customers",//Server端的Dll名稱以及對應的InfoCommand的名字,比如S001.InfoCommand1

                    0, //系統使用

                    "0",//組織代號

                    "" //附件

                    },

                new object[]{

                    "TestID",//TAble的鍵值欄位,如果是多個欄位組合的話,可以以分號隔開,比如:"OrderID;CustomerID"

                    "TestID=''" + TestID + "''"//key值組合,例如:"OrderID=10260;CustomerID=''A001''" A001左右分別是兩個單引號)

                }

            });

 

            SrvGL.LogUser(USERID, USERNAME, "WFPlus", -1); //登出

 

            if (ret[0].ToString() == "0")

            {

                return new object[] { 0, true };

            }

            else

            {

                return new object[] { 1, false };

            }           

        }

 

2. 請將此MethodName加入至ServiceManager元件中做設定,並建置專案。

3. 設定Scheduling:本例是以每天早上八點執行,設定如下。

 

 

4. 設定好並保存後,把右下角功能列中的Scheduling按右鍵,選擇【Active】即完成。

 

 


Top of Page