www.pudn.com > WorkflowDesigner.rar > ActivityInfoDlg.cs, change:2007-11-25,size:38522b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
using WorkflowDesigner; 
using System.Collections; 
namespace WorkflowDesigner.Designer 
{ 
    public partial class ActivityInfoDlg : Form 
    { 
        public ActivityInfoDlg(WfActivity wfactivity) 
        { 
            InitializeComponent(); 
            this._wfActivity = wfactivity; 
        } 
 
        private WfActivity _wfActivity; 
        /// <summary> 
        /// 节点信息 
        /// </summary> 
        public WfActivity WfActivity 
        { 
            get { return _wfActivity; } 
            set { _wfActivity = value; } 
        } 
 
        private void ActivityInfoDlg_Load(object sender, EventArgs e) 
        { 
            this.textBoxName.Text = this._wfActivity.Name.ToString(); 
            this.textBoxPosx.Text = this._wfActivity.X.ToString(); 
            this.textBoxPosY.Text = this._wfActivity.Y.ToString(); 
            //绑定角色信息 
            BindRoleInfo(); 
            //绑定之前的节点信息 
            BindBeforeActivity(); 
            
            //************赋值 
            LoadWorkInfo(); 
            LoadNormalInfo(); 
            LoadUserInfo(); 
 
            LoadAppInfo(); 
            //绑定应用信息 
            BindAppsInfo(); 
 
            LoadParamInfo(); 
            //绑定参数信息 
            BindParamsInfo(); 
        } 
 
        #region 读取时限信息 
        private void LoadWorkInfo() 
        { 
          
            if (this._wfActivity.Workday != 0) 
            { 
                this.checkBoxIsWorkday.Checked = true; 
                this.textBoxMustTime.Enabled = true; 
                this.checkBoxIsWarningDay.Enabled = true; 
            } 
            if (this._wfActivity.Warning_time != 0) 
            { 
                this.checkBoxIsWarningDay.Checked = true; 
                this.textBoxWarningTime.Enabled = true; 
            } 
            this.textBoxMustTime.Text = this._wfActivity.Workday.ToString("0.00"); 
            this.textBoxWarningTime.Text = this._wfActivity.Warning_time.ToString("0.00"); 
            //GetMartTemplet(); 
 
 
        } 
        #endregion 
 
        #region 读取节点所属用户信息 
        private WfRole GetRoleInfoByRoleName(String RoleName) 
        { 
            foreach (WfRole vo in  Program.WorkflowControl.WfPackageDocument.RoleList) 
            { 
                if (vo.Name == RoleName) 
                { 
                    return vo; 
                } 
            } 
            return null; 
        } 
        private WfActivity GetActivityByName(String Name) 
        { 
            foreach (DesignerVisualObject vo in this._wfActivity.Flow.VisualObjectList) 
            { 
                if (vo is WfActivity) 
                { 
 
                    if ((vo as WfActivity).Name == Name) 
                    { 
                        return (WfActivity)vo; 
                    } 
                } 
            } 
            return null; 
        } 
        private void LoadUserInfo() 
        { 
           
            this.radioButtonSelectRole.Checked = false; 
            this.radioButtonBeforActiv.Checked = false; 
            this.comboBoxRole.Enabled = false; 
            this.comboBoxPrevActive.Enabled = false; 
            if (this._wfActivity.IsSelectUser == 0) 
            { 
                //选择角色 
                this.radioButtonSelectRole.Checked = true; 
                this.comboBoxRole.Enabled = true; 
                
                if (this._wfActivity.Role != null) 
                { 
                    this.comboBoxRole.SelectedValue = this._wfActivity.Role.Name; 
                } 
                else 
                { 
                    this.comboBoxRole.Text = ""; 
                    this.comboBoxRole.SelectedValue = ""; 
                } 
            } 
            else 
            {  
                //选择之前节点 
                this.radioButtonBeforActiv.Checked = true; 
                this.comboBoxPrevActive.Enabled = true; 
 
                if (this._wfActivity.Before_ActiveInfo != null) 
                { 
                    this.comboBoxRole.SelectedValue = this._wfActivity.Before_ActiveInfo.Name; 
                } 
                else 
                { 
                    this.comboBoxPrevActive.Text = ""; 
                    this.comboBoxPrevActive.SelectedValue = ""; 
                } 
            } 
            
        } 
        #endregion 
 
        #region 读取一般信息 
        private void LoadNormalInfo() 
        { 
            this.checkBoxIsEnableSendBack.Checked = true; 
            this.checkBoxIsSendSelf.Checked = true; 
            if (this._wfActivity.IsSendBack == 0) 
            { 
                this.checkBoxIsEnableSendBack.Checked = false; 
            } 
            if (this._wfActivity.IsSendSelf == 0) 
            { 
                this.checkBoxIsSendSelf.Checked = false; 
            } 
 
            this.textBoxAfterSend.Text = this._wfActivity.AfterSend_Event; 
            this.textBoxBeforRecive.Text = this._wfActivity.BeforeRecive_Event; 
 
 
        } 
        #endregion 
 
        #region 读取应用信息 
        private void LoadAppInfo() 
        {  
            //得到已选择的应用信息 
           IList<WfApplication> apps = this._wfActivity.AppList; 
          // this.listBoxSlectedAppInfo.DataSource = apps; 
           this.listBoxSlectedAppInfo.DisplayMember = "Name"; 
           this.listBoxSlectedAppInfo.ValueMember = "Name"; 
           foreach (WfApplication app in apps) 
           { 
               this.listBoxSlectedAppInfo.Items.Add(app); 
           } 
 
        } 
        #endregion 
 
        #region 读取参数信息 
        private void LoadParamInfo() 
        { 
            //得到已选择的应用信息 
            IList<WfParam> Params = this._wfActivity.ParamsInfo; 
            // this.listBoxSlectedAppInfo.DataSource = apps; 
            this.listBoxSelectedParam.DisplayMember = "Name"; 
            this.listBoxSelectedParam.ValueMember = "Name"; 
            foreach (WfParam param in Params) 
            { 
                this.listBoxSelectedParam.Items.Add(param); 
            } 
        } 
        #endregion 
 
        #region 判断 
        private bool IsVaildSelectUser() 
        { 
            if (this.radioButtonSelectRole.Checked) 
            { 
 
                if (this.comboBoxRole.Text == "") 
                { 
                    MessageBox.Show("请选择节点角色!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                    this.comboBoxRole.Focus(); 
                    return false; 
                } 
                 
            } 
 
            if (this.radioButtonBeforActiv.Checked) 
            { 
                if (this.comboBoxPrevActive.Text == "") 
                { 
                    MessageBox.Show("请选择之前的节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                    this.comboBoxPrevActive.Focus(); 
                    return false; 
                } 
            } 
            return true; 
        } 
 
        private bool IsVaildWorkDay() 
        { 
            
            if (this.checkBoxIsWorkday.Checked) 
            { 
                if (this.textBoxMustTime.Text.Trim() == "") 
                { 
                    MessageBox.Show("请填写节点时限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                    this.textBoxMustTime.Focus(); 
                    return false; 
                } 
                else 
                { 
                    //判断输入的格式是否正确 
                    if (!CommFunction.IsWorkDay(this.textBoxMustTime.Text)) 
                    { 
                        MessageBox.Show("请填写正确节点所需时间格式[00000.00]!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                        this.textBoxMustTime.Focus(); 
                        return false; 
                    } 
                    else if (Convert.ToDecimal(this.textBoxMustTime.Text.Trim()) == 0) 
                    { 
                        MessageBox.Show("请填写节点时限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                        this.textBoxMustTime.Focus(); 
                        return false; 
                    } 
                } 
            } 
            if (this.checkBoxIsWarningDay.Checked) 
            { 
                if (this.textBoxWarningTime.Text.Trim() == "") 
                { 
                    MessageBox.Show("请填写节点预警时限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                    this.textBoxWarningTime.Focus(); 
                    return false; 
                } 
                else 
                { 
                    //判断输入的格式是否正确 
                    if (!CommFunction.IsWorkDay(this.textBoxWarningTime.Text)) 
                    { 
                        MessageBox.Show("请填写正确节点预警时间格式[00000.00]!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                        this.textBoxMustTime.Focus(); 
                        return false; 
                    } 
                    else if (Convert.ToDecimal(this.textBoxWarningTime.Text.Trim()) == 0) 
                    { 
                        MessageBox.Show("请填写节点预警时限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
                        this.textBoxWarningTime.Focus(); 
                        return false; 
                    } 
                } 
            } 
            return true; 
        } 
        #endregion 
 
        #region 绑定信息 
        private void BindRoleInfo() 
        { 
            IList<WfRole> Roles = Program.WorkflowControl.WfPackageDocument.RoleList; 
            this.comboBoxRole.DataSource = Roles; 
            this.comboBoxRole.DisplayMember = "Name"; 
            this.comboBoxRole.ValueMember = "Name"; 
        } 
 
        private void BindAppsInfo() 
        { 
            IList<WfApplication> Apps =RefreshAppInfo(); 
            this.listBoxAppInfo.DataSource = Apps; 
            this.listBoxAppInfo.DisplayMember = "Name"; 
            this.listBoxAppInfo.ValueMember = "Name"; 
        } 
        private  IList<WfApplication>  RefreshAppInfo() 
        { 
              
            IList<WfApplication> Apps = Program.WorkflowControl.WfPackageDocument.AppList; 
            IList<WfApplication> result = new List<WfApplication>(); 
            result.Clear(); 
            //得到所有的信息 
 
            foreach (WfApplication app in Apps) 
            { 
                bool IsExists = false;            
                foreach (WfApplication appTemp in this.listBoxSlectedAppInfo.Items) 
                { 
 
                    if (app.Name == appTemp.Name) 
                    { 
                        IsExists = true; 
                        break; 
                        
                        
                    } 
                } 
                if (!IsExists) 
                     result.Add(app); 
 
            } 
            return result; 
        } 
        private void BindParamsInfo() 
        { 
            IList<WfParam> Params = RefreshParamInfo(); 
            this.listBoxParam.DataSource = Params; 
            this.listBoxParam.DisplayMember = "Name"; 
            this.listBoxParam.ValueMember = "Name"; 
        } 
        private IList<WfParam> RefreshParamInfo() 
        { 
 
            IList<WfParam> Params = Program.WorkflowControl.WfPackageDocument.ParamList; 
            IList<WfParam> result = new List<WfParam>(); 
            result.Clear(); 
            //得到所有的信息 
 
            foreach (WfParam param in Params) 
            { 
                bool IsExists = false; 
                foreach (WfParam paramTemp in this.listBoxSelectedParam.Items) 
                { 
 
                    if (param.Name == paramTemp.Name) 
                    { 
                        IsExists = true; 
                        break; 
 
 
                    } 
                } 
                if (!IsExists) 
                    result.Add(param); 
 
            } 
            return result; 
        } 
 
        private void BindBeforeActivity() 
        { 
            ArrayList albeforActiv = new ArrayList(); 
            this.GetBeforeActivity(this._wfActivity,ref albeforActiv); 
 
            DataTable dt = new DataTable(); 
            dt.Columns.Add("ID", typeof(String)); 
            dt.Columns.Add("Name", typeof(String)); 
 
            foreach (WfActivity act in albeforActiv) 
            {  
                 DataRow dr = dt.NewRow(); 
                 dr["ID"] = act.Name; 
                 dr["Name"] = act.Name; 
                dt.Rows.Add(dr); 
           
            } 
            this.comboBoxPrevActive.DataSource = dt; 
            this.comboBoxPrevActive.DisplayMember = "ID"; 
            this.comboBoxPrevActive.ValueMember = "Name"; 
 
        } 
 
        private void GetBeforeActivity(WfActivity act, ref ArrayList al) 
        { 
            //遍历路径 
            foreach (DesignerVisualObject vo in this._wfActivity.Flow.VisualObjectList) 
            { 
                if (vo is WfTransition) 
                { 
                    WfTransition trans = vo as WfTransition; 
                    if (trans.EndActivity == act) 
                    { 
                        //如果前一个节点是普通节点类型 
 
                        if (trans.StartActivity is WfActivity) 
                        { 
                            if (!al.Contains(trans.StartActivity)) 
                                al.Add(trans.StartActivity); 
                            GetBeforeActivity(trans.StartActivity as WfActivity, ref al); 
                        } 
                    } 
                } 
            } 
 
        } 
        #endregion 
   
        #region 时限事件 
        private void checkBoxIsWorkday_CheckedChanged(object sender, EventArgs e) 
        { 
            this.textBoxMustTime.Text = "0.00"; 
            this.checkBoxIsWorkday.Checked = this.checkBoxIsWorkday.Checked; 
            this.textBoxMustTime.Enabled = this.checkBoxIsWorkday.Checked; 
            this.checkBoxIsWarningDay.Enabled = this.checkBoxIsWorkday.Checked; 
            if (!this.checkBoxIsWorkday.Checked) 
            { 
                this.textBoxWarningTime.Text = "0.00"; 
                this.checkBoxIsWarningDay.Checked = false; 
                this.textBoxWarningTime.Enabled = false; 
            } 
             
        } 
 
        private void checkBoxIsWarningDay_CheckedChanged(object sender, EventArgs e) 
        { 
            this.textBoxWarningTime.Text = "0.00"; 
            this.checkBoxIsWarningDay.Checked = this.checkBoxIsWarningDay.Checked; 
            this.textBoxWarningTime.Enabled = this.checkBoxIsWarningDay.Checked; 
        } 
        #endregion 
 
        #region 通用事件 
 
        private void buttonCancel_Click(object sender, EventArgs e) 
        { 
            this.Close(); 
        } 
 
 
        private void buttonOk_Click(object sender, EventArgs e) 
        { 
            //判断并保存该流程信息 
            if (this.IsVaild()) 
            { 
                this.Save(); 
 
            } 
        } 
 
        private bool IsVaild() 
        { 
            if (!this.IsVaildWorkDay()) 
            { 
                return false; 
            } 
            if (!this.IsVaildSelectUser()) 
            { return false; } 
            return true; 
        } 
 
        private void Save() 
        { 
 
            //保存填写的信息 
            try 
            { 
               // Program.WorkflowControl.UpdateFlow(_flow, this.textBoxName.Text, Convert.ToDouble(this.textBoxMustTime.Text), Convert.ToDouble(this.textBoxWarningTime.Text)); 
                //更新系统 
                //得到属性信息 
 
                this._wfActivity.Name = this.textBoxName.Text; 
                this._wfActivity.Workday = Convert.ToDouble(this.textBoxMustTime.Text); 
                this._wfActivity.Warning_time = Convert.ToDouble(this.textBoxWarningTime.Text); 
 
                 
                if (this.checkBoxIsEnableSendBack.Checked) 
                { 
                    this._wfActivity.IsSendBack = 1; 
                } 
                else 
                { 
                    this._wfActivity.IsSendBack = 0; 
                } 
                if (this.checkBoxIsSendSelf.Checked) 
                { 
                    this._wfActivity.IsSendSelf = 1; 
                } 
                else 
                { 
                    this._wfActivity.IsSendSelf = 0; 
                } 
 
                if (this.radioButtonSelectRole.Checked) 
                { 
 
                    if (this.comboBoxRole.SelectedValue.ToString() != "") 
                    { 
                        this._wfActivity.Role = this.GetRoleInfoByRoleName(this.comboBoxRole.SelectedValue.ToString()); 
                    } 
                    else 
                    { 
                        this._wfActivity.Role = null; 
                    } 
                    this._wfActivity.IsSelectUser = 0; 
 
                } 
 
                if (this.radioButtonBeforActiv.Checked) 
                { 
                    WfActivity activ = null ; 
                    if (this.comboBoxPrevActive.SelectedValue.ToString() != "") 
                    { 
                        this._wfActivity.Before_ActiveInfo = this.GetActivityByName(this.comboBoxPrevActive.SelectedValue.ToString()); 
                    } 
                    else 
                    { 
                        this._wfActivity.Before_ActiveInfo = null; 
                    } 
                    this._wfActivity.IsSelectUser = 1; 
                } 
                 
                this._wfActivity.AfterSend_Event=this.textBoxAfterSend.Text; 
                this._wfActivity.BeforeRecive_Event=this.textBoxBeforRecive.Text ; 
 
                IList<WfApplication> Applist = new List<WfApplication>(); 
                //保存应用信息 
                foreach (WfApplication app in listBoxSlectedAppInfo.Items) 
                { 
                    Applist.Add(app); 
                } 
 
                this._wfActivity.AppList = Applist; 
 
 
 
                IList<WfParam> paramlist = new List<WfParam>(); 
                //保存应用信息 
                foreach (WfParam param in this.listBoxSelectedParam.Items) 
                { 
                    paramlist.Add(param); 
                } 
 
                this._wfActivity.ParamsInfo = paramlist; 
 
 
                MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
                this.Close(); 
            } 
            catch (Exception err) 
            { 
                MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); 
            } 
 
 
 
        } 
#endregion 
 
        #region 用户选择事件 
        
        private void radioButtonSelectRole_CheckedChanged(object sender, EventArgs e) 
        { 
           
            if (this.radioButtonSelectRole.Checked) 
            { 
                this.radioButtonSelectRole.Checked = true; 
                this.comboBoxRole.Enabled = true; 
                this.radioButtonBeforActiv.Checked = false; 
                this.comboBoxPrevActive.Enabled = false; 
                this.comboBoxPrevActive.Text = ""; 
                this.comboBoxPrevActive.SelectedValue = ""; 
            } 
             
        } 
 
        private void radioButtonBeforActiv_CheckedChanged(object sender, EventArgs e) 
        { 
 
            
            if (this.radioButtonBeforActiv.Checked) 
            { 
                this.radioButtonSelectRole.Checked = false; 
                this.comboBoxRole.Enabled = false; 
                this.radioButtonBeforActiv.Checked = true; 
                this.comboBoxPrevActive.Enabled = true; 
                this.comboBoxRole.Text = ""; 
                this.comboBoxRole.SelectedValue = ""; 
            } 
        } 
        #endregion 
 
        #region 应用按钮事件 
 
        private void buttonTop_Click(object sender, EventArgs e) 
        { 
            //将选中的项位置上移一格 
            ArrayList al = new ArrayList(); 
            //得到选中的最小pos 
            int fistPos = GetMaxMinPos(out al, false); 
 
            this.SortTopButtom(fistPos, al, 1, true); 
            SetListBoxFouces(al); 
        } 
 
        private void buttonButtom_Click(object sender, EventArgs e) 
        { 
            //将选中的项位置上移一格 
            ArrayList al = new ArrayList(); 
            //得到选中的最大pos 
            int fistPos = GetMaxMinPos(out al, true); 
            //根据最大的排序 
 
 
            //fistPos = fistPos + 1; 
 
            this.SortTopButtom(fistPos, al, 1, false); 
            SetListBoxFouces(al); 
        } 
 
        private void buttonAdd_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxAppInfo.SelectedItems.Count > 0) 
            { 
                this.AddAppInfo(); 
            } 
            else 
            { 
                MessageBox.Show("没有应用信息可以添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            this.BindAppsInfo(); 
        } 
 
        private void buttonDelete_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxSlectedAppInfo.SelectedItems.Count > 0) 
            { 
                this.DeleteSelectAppInfoBySelectApp(); 
            } 
            else 
            { 
                MessageBox.Show("请选择要删除的应用信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindAppsInfo(); 
        } 
 
        private void buttonAddAll_Click(object sender, EventArgs e) 
        { 
 
            if (this.listBoxAppInfo.Items.Count > 0) 
            { 
                this.AddAllAppInfo(); 
            } 
            else 
            { 
                MessageBox.Show("没有应用信息可以添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindAppsInfo(); 
        } 
 
        private void buttonDeleteAll_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxSlectedAppInfo.Items.Count > 0) 
            { 
                this.DeleteAllSelectAppInfo(); 
            } 
            else 
            { 
                MessageBox.Show("请选择要删除的应用信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindAppsInfo(); 
        } 
        #endregion 
 
        #region 列表操作 
         
        private bool IsExistsAppInfo(String AppName) 
        { 
 
            foreach (WfApplication drv in this.listBoxSlectedAppInfo.Items) 
            { 
                String Name = drv.Name; 
 
                if (Name == AppName) 
                { 
                    return true; 
                } 
            } 
 
            return false; 
        } 
        private void AddAppInfo() 
        { 
            foreach (WfApplication drv in this.listBoxAppInfo.SelectedItems) 
            { 
                String AppName = drv.Name; 
                 
                if (!IsExistsAppInfo(AppName)) 
                { 
 
                    this.listBoxSlectedAppInfo.Items.Add((object)drv); 
                } 
 
 
            } 
        } 
        private void AddAllAppInfo() 
        { 
            //this.listBoxAppInfo.Items.Clear(); 
            foreach (WfApplication drv in this.listBoxAppInfo.Items) 
            { 
                String AppName = drv.Name; 
                 
                if (!IsExistsAppInfo(AppName)) 
                { 
 
                    this.listBoxSlectedAppInfo.Items.Add((object)drv); 
                } 
 
 
            } 
        } 
        private void DeleteAllSelectAppInfo() 
        { 
            ArrayList al = new ArrayList(); 
            foreach (WfApplication drv in listBoxSlectedAppInfo.Items) 
            { 
                al.Add(drv); 
            } 
            foreach (WfApplication drv in al) 
            { 
                listBoxSlectedAppInfo.Items.Remove((object)drv); 
            } 
        } 
 
        private void DeleteSelectAppInfoBySelectApp() 
        { 
 
            ArrayList al = new ArrayList(); 
            foreach (WfApplication drv in listBoxSlectedAppInfo.SelectedItems) 
            { 
                al.Add(drv); 
            } 
            foreach (WfApplication drv in al) 
            { 
                listBoxSlectedAppInfo.Items.Remove((object)drv); 
            } 
            // 
            //al.CopyTo(alTemp); 
        } 
        #endregion 
 
        #region 列表排序 
 
        private int GetMaxMinPos(out ArrayList al, bool IsMax) 
        { 
            al = new ArrayList(); 
            ArrayList alpos = new ArrayList();  
            int pos = this.listBoxSlectedAppInfo.SelectedIndex; 
            foreach (WfApplication drv in this.listBoxSlectedAppInfo.SelectedItems) 
            { 
                alpos.Add(this.listBoxSlectedAppInfo.Items.IndexOf(drv)); 
                int temppos = this.listBoxSlectedAppInfo.Items.IndexOf(drv); 
                if (IsMax) 
                { 
                    if (temppos > pos) 
                        pos = temppos; 
 
                } 
                else 
                { 
                    if (temppos < pos) 
                        pos = temppos; 
                } 
            } 
 
            for (int x = 0; x < alpos.Count; x++) 
            { 
                for (int y = 0; y < alpos.Count; y++) 
                { 
                    /* 
                    if (IsMax) 
                    { 
                        //逆序  因为插入的时候是反插的 
                        if ((int)alpos[x] > (int)alpos[y]) 
                        { 
                            int temp = (int)alpos[x]; 
                            alpos[x] = (int)alpos[y]; 
                            alpos[y] = temp; 
 
                        } 
                    } 
                    else 
                    { 
                        //逆序 因为插入的时候是反插的 
                        if ((int)alpos[x] > (int)alpos[y]) 
                        { 
                            int temp = (int)alpos[x]; 
                            alpos[x] = (int)alpos[y]; 
                            alpos[y] = temp; 
 
                        } 
                    }*/ 
                    if ((int)alpos[x] > (int)alpos[y]) 
                    { 
                        int temp = (int)alpos[x]; 
                        alpos[x] = (int)alpos[y]; 
                        alpos[y] = temp; 
 
                    } 
                } 
            } 
 
            foreach (int tempos in alpos) 
            { 
                al.Add(this.listBoxSlectedAppInfo.Items[tempos]); 
            } 
 
            return pos; 
        } 
 
        private void SortTopButtom(int TargtIndex, ArrayList al, int pos, bool IsMoveUP) 
        { 
            ArrayList oldListItem = new ArrayList(); 
            if (!IsMoveUP) 
            { 
                //保存原有的列表项 
                foreach (WfApplication drv in this.listBoxSlectedAppInfo.Items) 
                { 
 
                    oldListItem.Add(drv); 
                } 
 
            } 
            //删除所有数据 
            foreach (WfApplication drv in al) 
            { 
                this.listBoxSlectedAppInfo.Items.Remove(drv); 
            } 
            int count = 0; 
            foreach (WfApplication drv in al) 
            { 
                //判断是上移 还是下移 
                if (IsMoveUP) 
                { 
                    //如果上移如果移动的开始位置是第一个则在第一个插入即可 
                    if (TargtIndex <= 0) 
                    { 
                        this.listBoxSlectedAppInfo.Items.Insert(0, drv); 
                    } 
                    else 
                    { 
                        if (count == 0) 
                            TargtIndex = TargtIndex - pos; 
                        this.listBoxSlectedAppInfo.Items.Insert(TargtIndex, drv); 
 
                    } 
                } 
                else 
                { 
                    //如果下移 
                    if (TargtIndex >= this.listBoxSlectedAppInfo.Items.Count + al.Count - 1) 
                    { 
                        //drv要排正序 
                        if (count == 0) 
                        { 
                            //得到最小的焦点 并且-pos 
                            //得到目前的对象 
                            //加入个加的项 
                            this.listBoxSlectedAppInfo.Items.Add(drv); 
                            //在前面插入项 
                            this.listBoxSlectedAppInfo.Items.Insert(this.listBoxSlectedAppInfo.Items.Count - 1, drv); 
                            //删除最后项 
                            this.listBoxSlectedAppInfo.Items.RemoveAt(this.listBoxSlectedAppInfo.Items.Count - 1); 
 
                            TargtIndex = this.listBoxSlectedAppInfo.Items.Count - 1; 
 
                        } 
                        else 
                        { 
                            this.listBoxSlectedAppInfo.Items.Insert(this.listBoxSlectedAppInfo.Items.Count - 1, drv); 
                        } 
 
                    } 
                    else 
                    { 
                        if (count == 0) 
                        { 
                            //得到原来队列插的那个对象所在位置 
                            TargtIndex = TargtIndex + pos; 
                            //得到目前的对象 
                            int temppos = this.listBoxSlectedAppInfo.Items.IndexOf(oldListItem[TargtIndex]); 
                            TargtIndex = temppos + pos; 
 
                        } 
                        //drv要排逆序 
                        this.listBoxSlectedAppInfo.Items.Insert(TargtIndex, drv); 
 
                    } 
                } 
                count++; 
            } 
 
 
        } 
        private void SetListBoxFouces(ArrayList al) 
        { 
 
            foreach (WfApplication drv in al) 
            { 
 
                if (this.listBoxSlectedAppInfo.Items.Contains(drv)) 
                { 
                    this.listBoxSlectedAppInfo.SetSelected(this.listBoxSlectedAppInfo.Items.IndexOf(drv), true); 
 
                } 
            } 
        } 
        #endregion 
 
        #region 拖拽 
        private void listBoxSlectedAppInfo_DragDrop(object sender, DragEventArgs e) 
        { 
            //拖放完成 
 
            if (e.Data.GetDataPresent(typeof(WfApplication))) 
            { 
 
                WfApplication item = (WfApplication)e.Data.GetData(typeof(WfApplication)); 
 
 
                if (e.Effect == DragDropEffects.Move) 
                { 
 
                    System.Windows.Forms.ListBox lb = (ListBox)sender; 
 
                    Point clientPoint = this.listBoxSlectedAppInfo.PointToClient(new Point(e.X, e.Y)); 
 
                    //Point mouseDownLocation = new Point(e.X, e.Y); 
                    //新的位置 
                    int index = lb.IndexFromPoint(clientPoint); 
 
                    //原来的位置 
                    int oldindex = lb.Items.IndexOf(item); 
                    int temp = System.Math.Abs(oldindex - index); 
                    //将选中的项位置上移一格 
                    ArrayList al = new ArrayList(); 
                    if (index == -1) 
                    { 
                        temp = System.Math.Abs(oldindex - (this.listBoxSlectedAppInfo.Items.Count - 1)); 
 
                        //移到最后 
                        //向下移 
                        //得到选中的最大pos 
                        int fistPos = GetMaxMinPos(out al, true); 
                        //根据最大的排序 
 
                        this.SortTopButtom(this.listBoxSlectedAppInfo.Items.Count - 1, al, temp, false); 
                    } 
                    else 
                    { 
                        if (oldindex > index) 
                        { 
                            //向上移 
                            //得到选中的最大pos 
                            int fistPos = GetMaxMinPos(out al, false); 
                            //根据最大的排序 
 
                            this.SortTopButtom(fistPos, al, temp, true); 
 
                        } 
                        else if (oldindex < index) 
                        { 
                            //向下移 
                            //得到选中的最大pos 
                            int fistPos = GetMaxMinPos(out al, true); 
                            //根据最大的排序 
                            //如果位置大于等于数组本身 那么就放到最后 
                            if (index >= this.listBoxSlectedAppInfo.Items.Count - 1) 
                            { 
                                this.SortTopButtom(this.listBoxSlectedAppInfo.Items.Count - 1, al, temp, false); 
                            } 
                            else 
                            { 
 
                                this.SortTopButtom(fistPos, al, temp, false); 
                            } 
                        } 
                    } 
 
 
 
                    SetListBoxFouces(al); 
 
 
 
                    //this.textBox1.Text = item["UserName"].ToString();  
                    //触发交换位置 
                    //MessageBox.Show(item["UserName"].ToString()); 
 
 
                } 
            } 
        } 
 
        private void listBoxSlectedAppInfo_MouseDown(object sender, MouseEventArgs e) 
        { 
 
            if (e.Button == MouseButtons.Left) 
            { 
                System.Windows.Forms.ListBox lb = (ListBox)sender; 
 
                Point mouseDownLocation = new Point(e.X, e.Y); 
                int index = lb.IndexFromPoint(mouseDownLocation); 
                //int indexofitemundermousetodrag = this.listBoxSlectedAppInfo.IndexFromPoint(e.X, e.Y); 
                if (index != ListBox.NoMatches) 
                { 
                    lb.DoDragDrop(lb.Items[index], DragDropEffects.Move); 
                } 
            } 
 
 
 
        } 
 
        private void listBoxSlectedAppInfo_DragEnter(object sender, DragEventArgs e) 
        { 
            if (e.Data.GetDataPresent(typeof(WfApplication))) 
            { 
                e.Effect = DragDropEffects.Move; 
            } 
        } 
        #endregion  
        
        #region 参数列表 
        private bool IsExistsParamInfo(String ParamName) 
        { 
 
            foreach (WfParam drv in this.listBoxSelectedParam.Items) 
            { 
                String Name = drv.Name; 
 
                if (Name == ParamName) 
                { 
                    return true; 
                } 
            } 
 
            return false; 
        } 
        private void AddParamInfo() 
        { 
            foreach (WfParam drv in this.listBoxParam.SelectedItems) 
            { 
                String ParamName = drv.Name; 
 
                if (!IsExistsParamInfo(ParamName)) 
                { 
 
                    this.listBoxSelectedParam.Items.Add((object)drv); 
                } 
 
 
            } 
        } 
        private void AddAllParamInfo() 
        { 
            //this.listBoxAppInfo.Items.Clear(); 
            foreach (WfParam drv in this.listBoxParam.Items) 
            { 
                String ParamName = drv.Name; 
 
                if (!IsExistsParamInfo(ParamName)) 
                { 
 
                    this.listBoxSelectedParam.Items.Add((object)drv); 
                } 
 
 
            } 
        } 
        private void DeleteAllSelectParamInfo() 
        { 
            ArrayList al = new ArrayList(); 
            foreach (WfParam drv in listBoxSelectedParam.Items) 
            { 
                al.Add(drv); 
            } 
            foreach (WfParam drv in al) 
            { 
                listBoxSelectedParam.Items.Remove((object)drv); 
            } 
        } 
 
        private void DeleteSelectParamInfoBySelectParam() 
        { 
 
            ArrayList al = new ArrayList(); 
            foreach (WfParam drv in listBoxSelectedParam.SelectedItems) 
            { 
                al.Add(drv); 
            } 
            foreach (WfParam drv in al) 
            { 
                listBoxSelectedParam.Items.Remove((object)drv); 
            } 
            // 
            //al.CopyTo(alTemp); 
        } 
        #endregion 
 
        #region 参数事件 
 
        private void buttonAddParam_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxParam.SelectedItems.Count > 0) 
            { 
                this.AddParamInfo(); 
            } 
            else 
            { 
                MessageBox.Show("没有参数信息可以添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            this.BindParamsInfo(); 
        } 
 
        private void buttonDeleteParam_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxSelectedParam.SelectedItems.Count > 0) 
            { 
                this.DeleteSelectParamInfoBySelectParam(); 
            } 
            else 
            { 
                MessageBox.Show("请选择要删除的参数信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindParamsInfo(); 
        } 
 
        private void buttonAddAllParam_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxParam.Items.Count > 0) 
            { 
                this.AddAllParamInfo(); 
            } 
            else 
            { 
                MessageBox.Show("没有参数信息可以添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindParamsInfo(); 
        } 
 
        private void buttonDeleteAllParam_Click(object sender, EventArgs e) 
        { 
            if (this.listBoxSelectedParam.Items.Count > 0) 
            { 
                this.DeleteAllSelectParamInfo(); 
            } 
            else 
            { 
                MessageBox.Show("请选择要删除的参数信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
            } 
            BindParamsInfo(); 
        } 
        #endregion 
 
    } 
}