<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBoxCommonOperDemo.aspx.cs" Inherits="BusinessDealUserConfig" %> <%@ Register Src="UCUserInfo.ascx" TagName="UCUserInfo" TagPrefix="uc" %> <%@ Register Src="UCEmployeeBar.ascx" TagName="UCEmployeeBar" TagPrefix="uc" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <uc:UCUserInfo ID="UCUserInfo" runat="server" /> <uc:UCEmployeeBar ID="UCEmployeeBar" runat="server" /> <asp:Label ID="lblTile" runat="server" Text='默认流程配置'></asp:Label> <hr /> <table> <tr> <td> <asp:DropDownList ID="ddlJobs" runat="server" DataSourceID="odsJobs" DataTextField="JobName" DataValueField="JobCode" AppendDataBoundItems="true" AutoPostBack="true"> <asp:ListItem Value="0">-请选择-</asp:ListItem> </asp:DropDownList> <br /> <asp:ListBox ID="lstUsers" runat="server" DataSourceID="odsUsers" DataTextField="UserName" DataValueField="UserId" Width="100" Height="100"></asp:ListBox> </td> <td> <asp:Button ID="btnAdd" runat="server" Text="添加" OnClick="btnAdd_Click" Style="height: 21px" /><br /> <asp:Button ID="btnDelete" runat="server" Text="删除" OnClick="btnDelete_Click" /> </td> <td> <asp:ListBox ID="lstDealUsers" runat="server" Width="100" Height="100" DataTextField="DealUserName" DataValueField="DealUserId"></asp:ListBox> </td> <td> <asp:Button ID="btnUp" runat="server" Text="向上" onclick="btnUp_Click" /><br /> <asp:Button ID="btnDown" runat="server" Text="向下" onclick="btnDown_Click" /> </td> </tr> <tr> <td colspan="4" style="text-align:center"> <asp:Button ID="btnSave" runat="server" Text="保存" onclick="btnSave_Click" /></td> </tr> </table> <asp:ObjectDataSource ID="odsJobs" runat="server" SelectMethod="GetJobInfos" TypeName="GFOA.Library.UserService"> </asp:ObjectDataSource> <asp:ObjectDataSource ID="odsUsers" runat="server" SelectMethod="GetEmployeesByJob" TypeName="GFOA.Library.UserService"> <SelectParameters> <asp:ControlParameter ControlID="ddlJobs" Name="jobCode" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:ObjectDataSource> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using GFOA.Library; public partial class BusinessDealUserConfig : System.Web.UI.Page { protected UserService _UserService = new UserService(); protected DealUserConfigService _DealUserConfigService = new DealUserConfigService(); /// <summary> /// 业务ID /// </summary> public Guid BusinessId { get { return new Guid(ViewState["BusinessId"].ToString()); } set { ViewState["BusinessId"] = value; } } public string BusinessName { get { return (string)ViewState["BusinessName"]; } set { ViewState["BusinessName"] = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } private void BindData() { lblTile.Text = Request["BusinessName"] + "——" + lblTile.Text; BusinessId = new Guid(Request["BusinessId"]); BusinessName = Request["BusinessName"]; List<DealUserConfig> dealUserConfigs = this._DealUserConfigService.GetByBusinessId(BusinessId); if (dealUserConfigs != null) { lstDealUsers.DataSource = dealUserConfigs; lstDealUsers.DataBind(); } } /// <summary> /// 添加 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { if (this.lstUsers.SelectedValue == "") { ScriptHelper.RegisterScript("alert('没有选中任何用户,请选择用户');window.history.back(-1);"); } else { lstDealUsers.Items.Add(lstUsers.SelectedItem); lstDealUsers.SelectedIndex = 0; } } /// <summary> /// 删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { if (this.lstDealUsers.SelectedValue == "") { ScriptHelper.RegisterScript("alert('没有选中任何用户,请选择用户');window.history.back(-1);"); } else { lstDealUsers.Items.Remove(lstDealUsers.SelectedItem); } } /// <summary> /// 向上 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUp_Click(object sender, EventArgs e) { if (lstDealUsers.SelectedIndex != 0) { ListItem tempListItem = lstDealUsers.Items[lstDealUsers.SelectedIndex - 1]; string text = tempListItem.Text; string value = tempListItem.Value; lstDealUsers.Items[lstDealUsers.SelectedIndex - 1].Text = lstDealUsers.SelectedItem.Text; lstDealUsers.Items[lstDealUsers.SelectedIndex - 1].Value = lstDealUsers.SelectedItem.Value; lstDealUsers.Items[lstDealUsers.SelectedIndex].Text = text; lstDealUsers.Items[lstDealUsers.SelectedIndex].Value = value; lstDealUsers.SelectedIndex = lstDealUsers.SelectedIndex - 1; lstDealUsers.DataBind(); } else { ScriptHelper.RegisterScript("alert('已经到顶了');window.history.back(-1);"); } } /// <summary> /// 向下 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDown_Click(object sender, EventArgs e) { if (lstDealUsers.SelectedIndex != lstDealUsers.Items.Count - 1) { ListItem tempListItem = lstDealUsers.Items[lstDealUsers.SelectedIndex + 1]; string text = tempListItem.Text; string value = tempListItem.Value; lstDealUsers.Items[lstDealUsers.SelectedIndex + 1].Text = lstDealUsers.SelectedItem.Text; lstDealUsers.Items[lstDealUsers.SelectedIndex + 1].Value = lstDealUsers.SelectedItem.Value; lstDealUsers.Items[lstDealUsers.SelectedIndex].Text = text; lstDealUsers.Items[lstDealUsers.SelectedIndex].Value = value; lstDealUsers.SelectedIndex = lstDealUsers.SelectedIndex + 1; lstDealUsers.DataBind(); } else { ScriptHelper.RegisterScript("alert('已经到底了');window.history.back(-1);"); } } /// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { this._DealUserConfigService.DeleteByBusinessId(BusinessId); List<DealUserConfig> DealUserConfigs = new List<DealUserConfig>(); int sortIndex =0; foreach (ListItem userItem in lstDealUsers.Items) { UserInfoProxy userInfoProxy = this._UserService.GetUserInfo(Convert.ToInt32(userItem.Value)); DealUserConfig dealUserConfig = new DealUserConfig(); dealUserConfig.Id = Guid.NewGuid(); dealUserConfig.BusinessId = BusinessId; dealUserConfig.DealUserJobCode = userInfoProxy.JobCode; dealUserConfig.DealUserJobName = this._UserService.GetJobInfoByCode(userInfoProxy.JobCode).JobName; dealUserConfig.DealUserId = Convert.ToInt32(userItem.Value); dealUserConfig.DealUserName = userItem.Text; dealUserConfig.SortIndex = sortIndex++; DealUserConfigs.Add(dealUserConfig); } this._DealUserConfigService.InsertDealUserConfigs(DealUserConfigs); ScriptHelper.MessageDialog("保存成功", "BusinessDealUserConfig.aspx?BusinessName="+BusinessName+"&BusinessId="+BusinessId); } }