예제 #1
0
        public void ForceTests()
        {
            GroupM <A> .Init();

            GroupM <B> .Init();

            GroupM <C> .Init();

            Manger.Init();
            Manger.Create <A>(0);
            Manger.Create <B>(1);
            Manger.Create <C>(2);
            DateTime d1 = DateTime.Now;
            //Group<C> t;
            Group <A> ta;

            for (int i = 0; i < 10000000; i++)
            {
                //t = GroupM<C>.group;//18
                //t = Manger.GetGroup<C>(2);//48
                ta = GroupM <A> .group;//18
                //ta = Manger.GetGroup<A>(0);//70
            }
            DateTime d2 = DateTime.Now;

            Console.WriteLine((d2 - d1).TotalMilliseconds);
        }
예제 #2
0
        public GroupM GetGroup(string groupID)
        {
            GroupDA groupDA = null;
            DataRow dr;
            var     g = new GroupM {
            };

            try
            {
                groupDA = new GroupDA();
                dr      = groupDA.GetGroups(groupID, Operation).Rows[0];

                g = new GroupM
                {
                    GroupID     = dr["GroupID"].ToString(),
                    GroupName   = dr["GroupName"].ToString(),
                    Description = dr["Description"].ToString(),
                    IsDeleted   = Convert.ToByte(dr["IsDeleted"]),
                };
            }
            finally
            {
                if (groupDA != null)
                {
                    groupDA.CloseConnection();
                }
            }
            return(g);
        }
예제 #3
0
    // iPage 第N頁
    // iSize 最大顯示數量
    public DataTable fnSelects(GroupM groupM, int iPage, int iSize)
    {
        int iStart = (iPage - 1) * iSize + 1;
        int iEnd   = iPage * iSize;

        string sCondition = "";

        sCondition += PublicApi.fnAddCondition("[group_id]", groupM.group_id);
        sCondition += PublicApi.fnAddCondition("[name]", groupM.name);

        string sAccountSql = fnGetAccountCondition(groupM.user);

        if (sAccountSql != "")
        {
            sCondition += " AND [group_id] IN " + sAccountSql;
        }

        string sInquireSql =
            "  SELECT [group_m].[NUM],   " +
            "         [group_m].[group_id],   " +
            "         [group_m].[name],   " +
            "         CONVERT(CHAR, [group_m].[create_datetime], 111) [create_datetime],   " +
            "         CONVERT(CHAR, [group_m].[modify_datetime], 111) [modify_datetime]   " +
            "  FROM   (SELECT Row_number() OVER(ORDER BY[" + groupM.order + "] ASC) NUM, " +
            "                  *   " +
            "          FROM   [MNDTgroup_master]   " +
            "          WHERE  1 = 1 " + sCondition + ") AS [group_m]  " +
            "  WHERE  NUM BETWEEN " + iStart.ToString() + " AND " + iEnd.ToString();

        return(PublicApi.fnGetDt(sInquireSql, "MNDT"));
    }
예제 #4
0
    public bool fnIsExist(GroupM groupM)
    {
        string sSql = "  SELECT COUNT([group_id])   " +
                      "  FROM   [MNDTgroup_master]   " +
                      "  WHERE  [group_id] = '" + groupM.group_id + "'   ";

        return(PublicApi.fnGetValue(sSql, "MNDT") == "1");
    }
예제 #5
0
    public string fnUpdate(GroupM groupM)
    {
        string sSql = "  UPDATE [dbo].[MNDTgroup_master]  " +
                      "     SET [name] = '" + groupM.name + "'  " +
                      "        ,[description] = '" + groupM.description + "'  " +
                      "        ,[modify_id] = '" + groupM.create_id + "'  " +
                      "        ,[modify_datetime] = GETDATE()  " +
                      "  WHERE [group_id] = '" + groupM.group_id + "' ";

        return(PublicApi.fnExecuteSQL(sSql, "MNDT"));
    }
예제 #6
0
    public string fnDelete(GroupM groupM)
    {
        string sDetailsSql = " SELECT COUNT([group_id]) FROM [MNDTgroup_details] WHERE [group_id] = '" + groupM.group_id + "' ";
        string sCount      = PublicApi.fnGetValue(sDetailsSql, "MNDT");

        if (sCount == "0")
        {
            string sSql = " DELETE [MNDTgroup_master] " +
                          " WHERE [group_id] = '" + groupM.group_id + "' ";
            return(PublicApi.fnExecuteSQL(sSql, "MNDT"));
        }
        return("錯誤訊息:明細資料大於一筆。");
    }
예제 #7
0
        /// <summary>
        /// Get all goup info
        /// </summary>
        /// <param name="groupID"></param>
        /// <param name="selectedGroupID"></param>
        /// <param name="selectedGroupName"></param>
        /// <returns></returns>
        private List <GroupM> GetAllGroup(string groupID, out string selectedGroupID, out string selectedGroupName)
        {
            selectedGroupID   = "";
            selectedGroupName = "";

            bool getGroupFisrstElement = false;

            if (groupID == null)
            {
                getGroupFisrstElement = true;
            }

            List <GroupM> groupList = new List <GroupM>();

            GroupDA   groupDA = null;
            DataTable dt      = new DataTable();

            try
            {
                groupDA = new GroupDA();
                dt      = groupDA.GetAllGroup(Operation);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr    = dt.Rows[i];
                    GroupM  group = new GroupM();
                    group.GroupID   = CommUtil.ConvertObjectToString(dr["GroupID"]);
                    group.GroupName = CommUtil.ConvertObjectToString(dr["GroupName"]);
                    groupList.Add(group);

                    if (i == 0 && getGroupFisrstElement)
                    {
                        selectedGroupID   = group.GroupID;
                        selectedGroupName = group.GroupName;
                    }

                    if (group.GroupID.Equals(groupID))
                    {
                        selectedGroupID   = group.GroupID;
                        selectedGroupName = group.GroupName;
                    }
                }
            }
            finally
            {
                if (groupDA != null)
                {
                    groupDA.CloseConnection();
                }
            }
            return(groupList);
        }
예제 #8
0
    public DataTable fnSelect(GroupM groupM)
    {
        string sSql = "  SELECT TOP 1 [group_id]  " +
                      "        ,[name]  " +
                      "        ,[description]  " +
                      "        ,[create_id]  " +
                      "        ,CONVERT(char, [create_datetime], 120) [create_datetime]  " +
                      "        ,[modify_id]  " +
                      "        ,CONVERT(char, [modify_datetime], 120) [modify_datetime]  " +
                      "  FROM [MNDTgroup_master]  " +
                      "  WHERE [group_id] = '" + groupM.group_id + "' ";

        return(PublicApi.fnGetDt(sSql, "MNDT"));
    }
예제 #9
0
    public string fnCount(GroupM groupM)
    {
        string sCondition = "";

        sCondition += PublicApi.fnAddCondition("[group_id]", groupM.group_id);
        sCondition += PublicApi.fnAddCondition("[name]", groupM.name);

        string sAccountSql = fnGetAccountCondition(groupM.user);

        if (sAccountSql != "")
        {
            sCondition += " AND [group_id] IN " + sAccountSql;
        }
        string sCountSql =
            "          SELECT COUNT([group_id])   " +
            "          FROM   [MNDTgroup_master]   " +
            "          WHERE  1 = 1 " + sCondition;
        string sPageSize = PublicApi.fnGetValue(sCountSql, "MNDT");

        return(sPageSize);
    }
예제 #10
0
    public string fnInsert(GroupM groupM)
    {
        string sSql = "  INSERT INTO [dbo].[MNDTgroup_master]  " +
                      "             ([group_id]  " +
                      "             ,[name]  " +
                      "             ,[description]  " +
                      "             ,[create_id]  " +
                      "             ,[create_datetime]  " +
                      "             ,[modify_id]  " +
                      "             ,[modify_datetime])  " +
                      "       VALUES  " +
                      "             ('" + groupM.group_id + "'  " +
                      "             ,'" + groupM.name + "'  " +
                      "             ,'" + groupM.description + "'  " +
                      "             ,'" + groupM.create_id + "'  " +
                      "             ,GETDATE()  " +
                      "             ,'" + groupM.create_id + "'  " +
                      "             ,GETDATE())  ";

        return(PublicApi.fnExecuteSQL(sSql, "MNDT"));
    }
예제 #11
0
        public ResultModel New(GroupM model)
        {
            ResultModel result = new ResultModel();
            DateTime    dt     = DateTime.Now;

            Dictionary <string, object> paramValues = new Dictionary <string, object>();

            paramValues.Add("GroupName", model.GroupName.Trim());
            paramValues.Add("Operation", Operation);
            paramValues.Add("SystemID", "S0001");
            paramValues.Add("Description", model.Description);
            paramValues.Add("CreatedBy", UserID);
            paramValues.Add("CreatedTime", dt);
            paramValues.Add("LastModifiedBy", UserID);
            paramValues.Add("LastModifiedTime", dt);
            paramValues.Add("NumOfUsers", 0);
            paramValues.Add("IsDeleted", 0);

            GroupDA groupDA = null;

            try
            {
                groupDA         = new GroupDA();
                result.Affected = groupDA.NewGroup(paramValues);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Exception = ex.Message;
            }
            finally
            {
                if (groupDA != null)
                {
                    groupDA.CloseConnection();
                }
            }

            return(result);
        }
예제 #12
0
        public ResultModel Edit(GroupM model)
        {
            ResultModel result = new ResultModel();

            Dictionary <string, object> saveData = new Dictionary <string, object>();

            saveData.Add("GroupName", model.GroupName.Trim());
            saveData.Add("Description", model.Description);
            saveData.Add("LastModifiedBy", UserID);
            saveData.Add("LastModifiedTime", DateTime.Now);

            if (model.IsDeleted == 1)
            {
                saveData.Add("IsDeleted", model.IsDeleted);
                saveData.Add("DeletedBy", UserID);
                saveData.Add("DeletedTime", DateTime.Now);
            }

            GroupDA groupDA = null;

            try
            {
                groupDA         = new GroupDA();
                result.Affected = groupDA.EditGroup(saveData, model.GroupID);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Exception = ex.Message;
            }
            finally
            {
                if (groupDA != null)
                {
                    groupDA.CloseConnection();
                }
            }
            return(result);
        }
예제 #13
0
    // sNum 排行
    public string fnSelectGroupId(GroupM groupM, string sNum)
    {
        string sCondition = "";

        sCondition += PublicApi.fnAddCondition("[group_id]", groupM.group_id);
        sCondition += PublicApi.fnAddCondition("[name]", groupM.name);

        string sAccountSql = fnGetAccountCondition(groupM.user);

        if (sAccountSql != "")
        {
            sCondition += " AND [group_id] IN " + sAccountSql;
        }

        string sSql = "  SELECT [group_m].[group_id]  " +
                      "  FROM   (SELECT Row_number() OVER (ORDER BY [" + groupM.order + "] ASC) NUM,   " +
                      "                  *   " +
                      "          FROM   [MNDTgroup_master]   " +
                      "          WHERE  1 = 1" + sCondition + ") AS [group_m]  " +
                      "  WHERE [group_m].[NUM] = '" + sNum + "' ";

        return(PublicApi.fnGetValue(sSql, "MNDT"));
    }
예제 #14
0
        public ActionResult Edit(GroupM model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var result = groupBL(true).Edit(model);

                    if (result.IsSuccess && result.Affected > 0)
                    {
                        return(RedirectToAction("List", "Group"));
                    }
                    else
                    {
                        ModelState.AddModelError("ErrorMessage", result.Exception);
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("ErrorMessage", ex.Message);
                }
            }
            return(View(model));
        }
예제 #15
0
 /// <summary>
 /// 获得排序语句
 /// </summary>
 /// <returns>排序T-Sql语句</returns>
 public string GetGroupStr()
 {
     return(GroupM.GetGroupStr());
 }