protected void cmdAddUser_Click(object sender, EventArgs e)
    {
        string[] userIds = this.txtUserToAdd.Value.Trim().Trim(';').Split(';');
        if (userIds != null && userIds.Length > 0)
        {
            using (ISession session = new Session())
            {
                DataSet ds = session.CreateObjectQuery("select max(UserSequnce) as UserSequnce,max(StepIndex) as StepIndex from OrderApproveDef where OrderTypeCode=?typeCode")
                    .Attach(typeof(OrderApproveDef))
                    .SetValue("?typeCode", this.OrderTypeCode, "OrderTypeCode")
                    .DataSet();
                int maxSeq = ds.Tables[0].Rows.Count <= 0 ? 0 : Magic.Framework.Utils.Cast.Int(ds.Tables[0].Rows[0]["UserSequnce"], 0);
                int maxIndex = ds.Tables[0].Rows.Count <= 0 ? 0 : Magic.Framework.Utils.Cast.Int(ds.Tables[0].Rows[0]["StepIndex"], 0);

                try
                {
                    session.BeginTransaction();
                    for (int i = 0; i < userIds.Length; i++)
                    {
                        int userId = Magic.Framework.Utils.Cast.Int(userIds[i], 0);
                        if (userId <= 0) continue;
                        OrderApproveDef def = new OrderApproveDef();
                        def.OrderTypeCode = this.OrderTypeCode;
                        def.UserID = userId;
                        def.UserSequnce = (++maxSeq);
                        def.StepIndex = (++maxIndex);
                        def.Create(session);
                    }
                    session.Commit();
                    WebUtil.ShowMsg(this, "ǩ���û���ӳɹ�");
                    this.QueryAndBindData(session);
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
        }
    }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName != "Save" && e.CommandName != "Delete")
        {
            WebUtil.ShowError(this, "��������");
            return;
        }
        if (this.repeatControl.Items.Count <= 0) return;

        IList<OrderApproveDef> defines = new List<OrderApproveDef>();
        foreach (RepeaterItem item in this.repeatControl.Items)
        {
            HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
            if (e.CommandName == "Delete" && chk.Checked) continue;
            HtmlInputText txt = item.FindControl("txtSeq") as HtmlInputText;
            int userId = Magic.Framework.Utils.Cast.Int(chk.Value, -1);
            if (userId <= 0)
            {
                WebUtil.ShowError(this, "�޷���ȡǩ���û����ϣ���͹���Ա��ϵ");
                return;
            }

            OrderApproveDef def = new OrderApproveDef();
            def.OrderTypeCode = this.OrderTypeCode;
            def.UserID = userId;
            def.UserSequnce = Magic.Framework.Utils.Cast.Int(txt.Value);
            defines.Add(def);
        }

        using (ISession session = new Session())
        {
            try
            {
                session.BeginTransaction();
                session.CreateEntityQuery<OrderApproveDef>()
                    .Where(Exp.Eq("OrderTypeCode", this.OrderTypeCode))
                    .Delete();
                this.SortDefines(defines);
                for (int i = 1; i <= defines.Count; i++)
                {
                    defines[i-1].StepIndex = i;
                    defines[i-1].Create(session);
                }
                session.Commit();
                if (e.CommandName == "Save")
                    WebUtil.ShowMsg(this, "ǩ��˳�򱣴�ɹ�");
                else
                    WebUtil.ShowMsg(this, "ѡ���ǩ����Ա�Ѿ�ɾ��");
                this.QueryAndBindData(session);
            }
            catch (Exception er)
            {
                session.Rollback();
                WebUtil.ShowError(this, er);
            }
        }
    }