⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addressbook.cs

📁 Source for web based email in Csharp
💻 CS
📖 第 1 页 / 共 2 页
字号:
				connectpassword = client.Password;
			}

			System.String searchfilter = addressbook["searchstring"].ToString();
			if ( client!=null )
				searchfilter=searchfilter.Replace("$USERNAME$", client.UserName);
			else
				searchfilter=searchfilter.Replace("$USERNAME$", System.String.Empty);
			System.Data.Common.DbDataAdapter adapter = GetDataAdapter(addressbook["type"].ToString(), connectstring, connectusername, connectpassword, searchfilter);
			if ( adapter!=null ) {
				try {
					if ( addressbook["type"].Equals("odbc") ) {
						System.Data.Odbc.OdbcCommandBuilder builder = new System.Data.Odbc.OdbcCommandBuilder(adapter as System.Data.Odbc.OdbcDataAdapter);
						adapter.Update(data);
						builder = null;
					} else if ( addressbook["type"].Equals("oledb") ) {
						System.Data.OleDb.OleDbCommandBuilder builder = new System.Data.OleDb.OleDbCommandBuilder(adapter as System.Data.OleDb.OleDbDataAdapter);
						adapter.Update(data);
						builder = null;
					}
				} catch ( System.Exception e ) {
					if ( log.IsErrorEnabled )
						log.Error(System.String.Concat("Error updating address book [", addressbook["name"], "] for user [", client.UserName, "]" ), e);
					error = true;
				}
			} else {
				error = true;
			}
			adapter = null;
			return !error;
		}

		protected void AddressBookDataGrid_DeleteCheckBox ( System.Object sender, System.EventArgs args ) {
			if ( this._delete_items==null )
				this._delete_items = new System.Collections.Specialized.StringCollection();
			if ( ((System.Web.UI.HtmlControls.HtmlInputCheckBox)sender).Checked )
				this._delete_items.Add (((System.Web.UI.HtmlControls.HtmlInputCheckBox)sender).Value);
		}
		protected void AddressBookDataGrid_Delete ( System.Object sender, System.Web.UI.WebControls.DataGridCommandEventArgs args ) {
			if ( this._delete_items!=null && this._delete_items.Count>0 ) {
				System.Collections.Specialized.ListDictionary addressbook = anmar.SharpWebMail.UI.AddressBook.GetAddressbook(this.addressbookselect.Value, Application["sharpwebmail/send/addressbook"]);
				System.Data.DataTable data = GetDataSource(addressbook, false, Session["client"] as anmar.SharpWebMail.IEmailClient);
				if ( data!=null ) {
					bool delete = false;
					System.Data.DataView view = data.DefaultView;
					foreach ( System.String item in this._delete_items ) {
						view.RowFilter = System.String.Concat(data.Columns[1].ColumnName, "='", item, "'");
						if ( view.Count==1 ) {
							view[0].Delete();
							delete = true;
						}
					}
					if ( delete ) {
						anmar.SharpWebMail.UI.AddressBook.UpdateDataSource(data, addressbook, Session["client"] as anmar.SharpWebMail.IEmailClient);
					}
				}
			}
		}
		protected void AddressBook_Changed ( System.Object sender, System.EventArgs args ) {
			this.AddressBookDataGrid.CurrentPageIndex = 0;
		}
		protected void AddressBookDataGrid_PageIndexChanged ( System.Object sender, System.Web.UI.WebControls.DataGridPageChangedEventArgs args ) {
			if ( args.NewPageIndex>=0 && args.NewPageIndex<this.AddressBookDataGrid.PageCount )
				this.AddressBookDataGrid.CurrentPageIndex = args.NewPageIndex;
		}
		protected void AddressBookNextPageButton_Click ( System.Object sender, System.Web.UI.ImageClickEventArgs args ) {
			if ( (this.AddressBookDataGrid.CurrentPageIndex+1)<this.AddressBookDataGrid.PageCount ) {
				AddressBookDataGrid_PageIndexChanged ( sender, new System.Web.UI.WebControls.DataGridPageChangedEventArgs ( sender, this.AddressBookDataGrid.CurrentPageIndex+1 ) );
			}
		}
		protected void AddressBookPrevPageButton_Click ( System.Object sender, System.Web.UI.ImageClickEventArgs args ) {
			if ( this.AddressBookDataGrid.CurrentPageIndex>0 ) {
				AddressBookDataGrid_PageIndexChanged (sender, new System.Web.UI.WebControls.DataGridPageChangedEventArgs ( sender, this.AddressBookDataGrid.CurrentPageIndex-1 ));
			}
		}
		protected void AddressBookDataGrid_Sort ( System.Object sender, System.Web.UI.WebControls.DataGridSortCommandEventArgs args ) {
			this.AddressBookDataGrid.CurrentPageIndex = 0;
			this._sort_expression = args.SortExpression;
		}
		protected void Page_Init () {
			this.EnsureChildControls();
			// Full page things
			if ( this.AddressBookDataGrid==null && this.SharpUI!=null ) {
				this.addressbookselect=(System.Web.UI.HtmlControls.HtmlSelect)this.SharpUI.FindControl("addressbookselect");
				this.AddressBookDataGrid=(System.Web.UI.WebControls.DataGrid)this.SharpUI.FindControl("AddressBookDataGrid");
				this.addressbooklabel=(System.Web.UI.WebControls.Label)this.SharpUI.FindControl("addressbookLabel");
				this.SharpUI.nextPageImageButton.Click += new System.Web.UI.ImageClickEventHandler(AddressBookNextPageButton_Click);
				this.SharpUI.prevPageImageButton.Click += new System.Web.UI.ImageClickEventHandler(AddressBookPrevPageButton_Click);
				this.SharpUI.refreshPageImageButton.Enabled = false;
				this.AddressBookDataGrid.PagerStyle.NextPageText = this.SharpUI.LocalizedRS.GetString("inboxNextPage");
				this.AddressBookDataGrid.PagerStyle.PrevPageText = this.SharpUI.LocalizedRS.GetString("inboxPrevPage");
			}
			
			if ( Application["sharpwebmail/send/addressbook"]!=null ) {
				System.Collections.SortedList addressbooks = (System.Collections.SortedList)Application["sharpwebmail/send/addressbook"];
				if ( addressbooks.Count>1 ) {
					addressbookselect.Visible = true;
					if ( this.addressbooklabel!=null )
						this.addressbooklabel.Visible = true;
				}
				addressbookselect.DataSource = addressbooks;
				addressbookselect.DataTextField = "Key";
				addressbookselect.DataValueField = "Key";
				addressbookselect.DataBind();
				if ( !this.IsPostBack ) {
					System.String book = Request.QueryString["book"];
					if ( book!=null && book.Length>0 ) {
						addressbookselect.Value = book;
					}
				}
			}
		}
		protected void Page_PreRender( System.Object sender, System.EventArgs args ) {
			System.Collections.Specialized.ListDictionary addressbook = GetAddressbook(addressbookselect.Value, Application["sharpwebmail/send/addressbook"]);
			if ( addressbook!=null && !addressbook["type"].Equals("none") ) {
				this.AddressBookDataGrid.PageSize = (int)addressbook["pagesize"];
				System.Data.DataTable data = GetDataSource(addressbook, false, Session["client"] as anmar.SharpWebMail.IEmailClient );
				if ( data!=null ) {
					if ( this._sort_expression!=null && this._sort_expression.Length>0 ) {
						if ( this._sort_expression.IndexOf("[NameColumn]")!=-1 ) {
							this._sort_expression = this._sort_expression.Replace("[NameColumn]", addressbook["NameColumn"].ToString());
						} else if ( this._sort_expression.IndexOf("[EmailColumn]")!=-1 ) {
							this._sort_expression = this._sort_expression.Replace("[EmailColumn]", addressbook["EmailColumn"].ToString());
						} else {
							this._sort_expression = null;
						}
						if ( this._sort_expression!=null )
							data.DefaultView.Sort = this._sort_expression;
					}
					this.AddressBookDataGrid.DataSource = data.DefaultView;
				}
				// Full Page Mode
				if ( this.SharpUI!=null ) {
					bool allowupdate = (bool)addressbook["allowupdate"];
					// Editable columns?
					if ( this.AddressBookDataGrid.Columns.Count>1 ) {
						this.AddressBookDataGrid.Columns[this.AddressBookDataGrid.Columns.Count-1].Visible = allowupdate;
						this.AddressBookDataGrid.Columns[this.AddressBookDataGrid.Columns.Count-2].Visible = allowupdate;
					}
					// Editable links?
					System.Web.UI.HtmlControls.HtmlAnchor link = (System.Web.UI.HtmlControls.HtmlAnchor)this.SharpUI.FindControl("addressbookEntryInsert");
					if ( link!=null ) {
						link.HRef = System.String.Concat("addressbook_edit.aspx?book=", System.Web.HttpUtility.UrlEncode(this.addressbookselect.Value));
						link.Visible = allowupdate;
					}
					// Editable links?
					link = (System.Web.UI.HtmlControls.HtmlAnchor)this.SharpUI.FindControl("addressbookImportExport");
					if ( link!=null ) {
						link.HRef = System.String.Concat("addressbook_data.aspx?book=", System.Web.HttpUtility.UrlEncode(this.addressbookselect.Value));
						link.Visible = allowupdate;
					}
				}
			}
			System.Resources.ResourceSet resources = (System.Resources.ResourceSet) Session["resources"];;
			// Pop-up mode
			if ( this.SharpUI==null ) {
				this.AddressBookDataGrid.Columns[0].HeaderText = resources.GetString("addressbookNameLabel");
			}
			this.AddressBookDataGrid.Columns[0].HeaderStyle.Wrap = false;
			this.AddressBookDataGrid.DataBind();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -