AccessoryModule.ascx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:4k
- namespace qminoa.Webs.Msg.module
- {
- using System;
- using System.Data;
- using System.Drawing;
- using System.Web;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- public abstract class AccessoryModule : System.Web.UI.UserControl
- {
- protected System.Web.UI.WebControls.TextBox txttAccessoryID;
- protected System.Web.UI.WebControls.TextBox txtAccessoryID;
- protected System.Web.UI.WebControls.Button btndelete;
- protected System.Web.UI.WebControls.DropDownList dopAccessory;
- protected System.Web.UI.WebControls.Label lblrace;
- protected System.Web.UI.WebControls.Label lblcont;
- protected System.Web.UI.WebControls.TextBox txtAccessory;
- protected System.Web.UI.WebControls.Label lblAccessory;
- protected System.Web.UI.WebControls.Button btnup;
- protected System.Web.UI.WebControls.Label lbltitle;
- protected System.Web.UI.WebControls.Label lblhead;
- protected System.Web.UI.HtmlControls.HtmlInputFile upaccessory;
- public string Accessory
- {
- get
- {
- return txtAccessory.Text;
- }
- set
- {
- txtAccessory.Text = value;
- }
- }
- public string AccessoryID
- {
- get
- {
- return txtAccessoryID.Text;
- }
- set
- {
- txtAccessoryID.Text = value;
- char [] seprator = new char [1];
- seprator[0] = ',';
- string [] acc = txtAccessory.Text.Split(seprator,10);
- string [] accid = txtAccessoryID.Text.Split(seprator,10);
- for(int i = 0 ; i < acc.Length; i ++)
- {
- dopAccessory.Items.Add(new ListItem(acc[i],accid[i]));
- }
- }
- }
- private void Page_Load(object sender, System.EventArgs e)
- {
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// 设计器支持所需的方法 - 不要使用
- /// 代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.btnup.Click += new System.EventHandler(this.btnup_Click);
- this.btndelete.Click += new System.EventHandler(this.btndelete_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void btnup_Click(object sender, System.EventArgs e)
- {
- if(upaccessory.PostedFile.FileName != "")
- {
- string convert;
- string strFullPath=upaccessory.PostedFile.FileName;
- string filename=strFullPath.Substring(strFullPath.LastIndexOf("\") + 1);
- string extent=filename.Substring(filename.LastIndexOf(".")+1);
- if(dopAccessory.Items.Count==1)
- {
- txtAccessory.Text+=filename;
- convert = DateTime.Now.ToString()+"."+extent;
- convert = convert.Replace(":","-");
- txtAccessoryID.Text += convert;
- dopAccessory.Items.Add(new ListItem(filename,convert.ToString()));
- filename=txtAccessoryID.Text;
- }
- else
- {
- txtAccessory.Text+=","+filename;
- convert = DateTime.Now.ToString()+"."+extent;
- convert = convert.Replace(":","-");
- txtAccessoryID.Text+=","+convert;
- dopAccessory.Items.Add(new ListItem(filename,convert.ToString()));
- filename=txtAccessoryID.Text.Substring(txtAccessoryID.Text.LastIndexOf(",")+1);
- }
- string path=Server.MapPath("file");
- upaccessory.PostedFile.SaveAs(path+"\"+filename);
- }
- }
- private void btndelete_Click(object sender, System.EventArgs e)
- {
- if(dopAccessory.SelectedItem.Value != "-1")
- {
- string fileString=txtAccessory.Text;
- string fileStringID = txtAccessoryID.Text;
- int index = dopAccessory.SelectedIndex;
- int pos = fileString.IndexOf(dopAccessory.SelectedItem.Text,0);
- int posid = fileStringID.IndexOf(dopAccessory.SelectedItem.Value,0);
- int length =dopAccessory.SelectedItem.Text.Length;
- int lengthid = dopAccessory.SelectedItem.Value.Length;
- if(dopAccessory.Items.Count>2)
- {
- if ( 0 != pos)
- {
- fileString = fileString.Remove(pos-1,length);
- fileStringID = fileStringID.Remove(posid-1,lengthid);
- }
- else
- {
- fileString = fileString.Remove(pos,length);
- fileStringID = fileStringID.Remove(posid,lengthid);
- }
- }
- else
- {
- fileString = fileString.Remove(pos,length);
- fileStringID = fileStringID.Remove(pos,lengthid);
- }
- txtAccessory.Text = fileString;
- txtAccessoryID.Text = fileStringID;
- dopAccessory.Items.Remove(new ListItem(dopAccessory.SelectedItem.Text,
- dopAccessory.SelectedItem.Value));
- }
- }
- }
- }