📄 selectreceiver.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace OI.recordFile
{
/// <summary>
/// selectReceiver 的摘要说明。
/// </summary>
public class selectReceiver : OI.PageBase
{
protected int RecordFileID;
protected System.Web.UI.WebControls.Button ButtonAdd;
protected System.Web.UI.WebControls.Button ButtonRemove;
protected System.Web.UI.WebControls.ListBox ListBoxSUsers;
protected System.Web.UI.WebControls.ListBox ListBoxRUsers;
protected OI.UserControls .Department SelectedDep;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.ImageButton ImageButton2;
protected System.Web.UI.WebControls.ImageButton ImageButton3;
protected System.Web.UI.WebControls.Label LabelMsg;
protected OI.DatabaseOper .DatabaseConnect Dbc=new OI.DatabaseOper.DatabaseConnect ();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["userid"]==null)
{
Response.Write ("<script>window.location.href='../userpass.aspx'</script>");
return;
}
if(!Page.IsPostBack )
{
try
{
RecordFileID=int.Parse(Request.QueryString ["id"].ToString ());
ViewState["RecordFileID"]=RecordFileID.ToString ();
}
catch
{
Response.Redirect ("sendFileList.aspx");
}
//BindSUsers();
//BindRUsers();
}
}
private void BindSUsers(int depID)
{
string sql="select userid,username from accounts_users where departmentid='"+depID+"'";//where userid not in( select userid from filegive ) ";
DataSet ds=new DataSet ();
ds=Dbc.getBinding (sql,"t");
ListBoxSUsers.Items .Clear ();
if (ds.Tables[0].Rows .Count >0)
{
ListBoxSUsers.DataSource =ds.Tables[0].DefaultView ;
ListBoxSUsers.DataTextField =ds.Tables[0].Columns ["username"].ToString ();
ListBoxSUsers.DataValueField =ds.Tables[0].Columns ["userid"].ToString ();
ListBoxSUsers.DataBind ();
}
}
private void BindRUsers()
{
string sql ="select f.userid,a.username from filegive f,accounts_users a where f.userid=a.userid and f.RecordFileID="+ViewState["RecordFileID"].ToString ();
DataSet ds=new DataSet ();
ds=Dbc.getBinding (sql,"t");
if (ds.Tables[0].Rows .Count >0)
{
ListBoxRUsers.DataSource =ds.Tables[0].DefaultView ;
ListBoxRUsers.DataTextField =ds.Tables[0].Columns ["username"].ToString ();
ListBoxRUsers.DataValueField =ds.Tables[0].Columns ["userid"].ToString ();
ListBoxRUsers.DataBind ();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
this.ButtonRemove.Click += new System.EventHandler(this.ButtonRemove_Click);
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.ImageButton3.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton3_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void ButtonAdd_Click(object sender, System.EventArgs e)
{
if (ListBoxSUsers.SelectedIndex <0)
{
Page.RegisterStartupScript ("","<script>alert('请选择人员')</script>");
return ;
}
ListBoxRUsers.SelectedIndex =-1;
foreach(ListItem li in ListBoxSUsers.Items )
{
if(li.Selected &&(ListBoxRUsers.Items .FindByValue (li.Value )==null))
{
ListBoxRUsers.Items .Add (li);
}
}
ListBoxSUsers.SelectedIndex =-1;
ListBoxRUsers.SelectedIndex =-1;
// ListItem li=ListBoxSUsers.SelectedItem;
// ListBoxSUsers.Items .Remove (li);
// ListBoxRUsers.Items .Add (li);
}
private void ButtonRemove_Click(object sender, System.EventArgs e)
{
if (ListBoxRUsers.SelectedIndex <0)
{
Page.RegisterStartupScript ("","<script>alert('请选择人员')</script>");
return ;
}
// foreach(ListItem li in ListBoxRUsers.Items )
// {
// if(li.Selected )
// ListBoxRUsers.Items .Remove (li);
// }
int nCount=0;
foreach(ListItem li in ListBoxRUsers.Items )
{
if(li.Selected )
{
nCount++ ;
}
}
string[] strText=new string [nCount];
nCount=0;
foreach(ListItem li in ListBoxRUsers.Items )
{
if(li.Selected )
{
strText[nCount++]=li.Value ;
}
}
for(int i=0;i<nCount;i++)
{
ListBoxRUsers.Items .Remove (ListBoxRUsers.Items .FindByValue (strText[i]));
}
ListBoxRUsers.SelectedIndex =-1;
// ListBoxSUsers.SelectedIndex =-1;
// ListItem li=ListBoxRUsers.SelectedItem;
// ListBoxSUsers.Items .Add (li);
// ListBoxRUsers.Items .Remove (li);
}
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
int nDepID=SelectedDep.DEPT_ID ;
BindSUsers(nDepID);
}
private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if (ListBoxRUsers.Items .Count <1)
{
Page.RegisterStartupScript ("","<script>alert('请选择接收人');</script>");
return;
}
foreach (ListItem li in ListBoxRUsers.Items )
{
string Sql="select count(*) from filegive where RecordFileID="+ViewState["RecordFileID"].ToString ();
Sql+= " and userid=" + li.Value ;
if (int.Parse (Dbc.GetValueBySql (Sql))< 1)
{
string sqladd="insert into filegive (RecordFileID,UserID,SenderID,SendTime) values (" + ViewState["RecordFileID"].ToString () +","+li.Value +","+Session["userid"].ToString ()+",'"+System.DateTime .Now +"')";
Dbc.ExecuteSQL (sqladd);
}
Page.RegisterStartupScript ("","<script>alert('文件传送成功');window.location.href='sendFileList.aspx';</script>");
}
}
private void ImageButton3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
System.Collections.ArrayList al=new System.Collections.ArrayList();
try{
if (ListBoxRUsers.Items .Count <1) {
Page.RegisterStartupScript ("","<script>alert('请选择接收人');</script>");
return;
}
string strSqlTitle="SELECT title from RecordFile where RecordFileID='"+ViewState["RecordFileID"].ToString ()+"'";
ArrayList tempAL=Dbc.getData (strSqlTitle);
string strTitle="";
if(tempAL.Count >0)
strTitle=tempAL[0].ToString ();
foreach (ListItem li in ListBoxRUsers.Items ) {
string Sql="select count(*) from filegive where RecordFileID="+ViewState["RecordFileID"].ToString ();
Sql+= " and userid=" + li.Value ;
if (int.Parse (Dbc.GetValueBySql (Sql))< 1) {
string sqladd="insert into filegive (RecordFileID,UserID,SenderID,SendTime) values (" + ViewState["RecordFileID"].ToString () +","+li.Value +","+Session["userid"].ToString ()+",'"+System.DateTime .Now +"')";
string sqlupdate="update RecordFile set isSent='1' where RecordFileID='"+ViewState["RecordFileID"].ToString ()+"'";
string strSql="INSERT INTO message(SendUserId, ReceiveUserId, FileTable,MessageContent) "+
"VALUES('"+Session["userid"].ToString ()+"','"+li.Value +"','filegive','"
+"在“文件传阅”中,公文《"+strTitle+"》未处理!')";
al.Add((object)sqladd);
al.Add((object)sqlupdate);
al.Add ((object)strSql);
//Dbc.ExecuteTransaction(al);
}
}
Dbc.ExecuteTransaction(al);
Page.RegisterStartupScript ("","<script>alert('文件传送成功');window.location.href='sendFileList.aspx';</script>");
}
catch(System.Exception err){
LabelMsg.Text=err.Message;
LabelMsg.Visible=true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -