addproduct.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;
using  System.IO;
using  Shop.SystemControls;
using  System.Data.SqlClient;
using  System.Drawing.Imaging;
using  Shop.Systemcontrols;
using  System.Xml;
using  System.Text;
using  picmark;

namespace  Shop.Controls
{
    
/// <summary>
    
/// addproduct 的摘要说明。
    
/// </summary>

    public class addproduct:TemplatedWebControl
    
{
        
public string sql,name2,StrPath;
        
protected DataSet ds = new DataSet();
        
protected Systemcontrols.DAL.product dbproduct = new Shop.Systemcontrols.DAL.product();
        
protected Systemcontrols.DAL.bigclass dbbigclass = new Shop.Systemcontrols.DAL.bigclass();
        
protected Systemcontrols.DAL.author dbauthor = new Shop.Systemcontrols.DAL.author();
        
protected Systemcontrols.DAL.year dbyear = new Shop.Systemcontrols.DAL.year();
        
protected System.Web.UI.WebControls.TextBox temp;
        TextBox TextBox1;
        TextBox TextBox2;
        TextBox TextBox4;
        TextBox TextBox6;
        TextBox TextBox7;
        DropDownList DropDownList1;
        DropDownList DropDownList2;
        DropDownList DropDownList3;
        DropDownList DropDownList4;
        Button Button1;
        Button Button2;
        Label Label9;
        HtmlInputFile fileup1;
        
private string AllowExtendName = ".JPEG|.JPE|.JPG";    // 允许的文件扩展名称。大写
        public addproduct()
        
{
            StrPath 
= HttpContext.Current.Server.MapPath("../fpv/fpv_xmls/photos.xml");
        }


        
method

        
private void down1_bind()
        
{
            DropDownList1.DataTextField 
= "name";
            DropDownList1.DataValueField 
= "Big_classid";
            DropDownList1.DataSource 
= dbbigclass.GetList();
            DropDownList1.DataBind();
//            DropDownList1.Items.Insert(0,new ListItem("请选择",""));
        }


        
private void myinit2()
        
{
            DropDownList3.DataTextField 
= "author_name";
            DropDownList3.DataValueField 
= "id";
            DropDownList3.DataSource 
= dbauthor.GetList();
            DropDownList3.DataBind();
            DropDownList3.Items.Insert(
0,new ListItem("请选择",""));
        }


        
private void myinit3()
        
{
            DropDownList4.DataTextField 
= "name";
            DropDownList4.DataValueField 
= "id";
            DropDownList4.DataSource 
= dbyear.GetList();
            DropDownList4.DataBind();
            DropDownList4.Items.Insert(
0,new ListItem("请选择",""));
        }


        
protected override void AttachChildControls()
        
{
            TextBox1 
= (TextBox)FindControl("TextBox1");
            TextBox2 
= (TextBox)FindControl("TextBox2");
            TextBox4 
= (TextBox)FindControl("TextBox4");
            TextBox6 
= (TextBox)FindControl("TextBox6");
            TextBox7 
= (TextBox)FindControl("TextBox7");
            Button1 
= (Button)FindControl("Button1");
            Button2 
= (Button)FindControl("Button2");
            DropDownList1 
= (DropDownList)FindControl("DropDownList1");
            DropDownList2 
= (DropDownList)FindControl("DropDownList2");
            DropDownList3 
= (DropDownList)FindControl("DropDownList3");
            DropDownList4 
= (DropDownList)FindControl("DropDownList4");
            Button1.Click 
+= new EventHandler(Button1_Click);
            Button2.Click 
+= new EventHandler(Button2_Click);
            fileup1 
= (HtmlInputFile)FindControl("fileup1");
            Label9 
= (Label)FindControl("Label9");
            temp 
= (System.Web.UI.WebControls.TextBox)FindControl( "temp" );

            StringBuilder sbHidden 
= new StringBuilder( );
            sbHidden.Append( 
"<script language = javascript >" );
            sbHidden.Append( 
"    document.getElementById( \"" + temp.ClientID + "\" ).style.visibility = \"hidden\";" );
            sbHidden.Append( 
"</script>" );
            
this.Page.RegisterStartupScript( "", sbHidden.ToString( ));

            DropDownList2.Attributes.Add( 
"OnChange""AttachValue( );" );
            script();
            
if (!Page.IsPostBack)
            
{
                myinit2();
                myinit3();
                down1_bind();
                DropDownList1.Attributes.Add(
"onchange","XmlPost2(this);");
            }

            
if(big != "")
          
{
            down2_bind(big);
          }

        }

        
脚本

        
上传图片

        
// 获取一个随机的文件名称
        private string GetRandomFileName()
        
{
            
string strData = DateTime.Now.ToString("yyyyMMddHHmmss"); 
            strData 
+= System.Guid.NewGuid();
            
return strData;
        }



        
// 检查文件类型是否有效
        private bool CheckValidExt(string extendName)
        
{
            
bool isValid = false;
            extendName 
= extendName.ToUpper();
            
string[] extends = AllowExtendName.Split('|');
            
foreach(string extend in extends)
            
{
                
if(extend == extendName)
                
{
                    isValid 
= true;
                    
break;
                }

            }
   
            
return isValid;
        }


        
添加产品

        
private void down2_bind(string id)
        
{
          
string mystr = "";
            ds 
= dbproduct.GetDropDownList(Int32.Parse(id));
          
if(ds.Tables[0].Rows.Count != 0)
          
{
                mystr 
+= ",|请选择";
            
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
            
{
              mystr 
+= "," + ds.Tables[0].Rows[i]["small_classid"].ToString() + "|" + ds.Tables[0].Rows[i]["name2"].ToString();
            }

            mystr 
= mystr.Substring(1);
          }

          HttpContext.Current.Response.Write(mystr);
          HttpContext.Current.Response.End();
        }


        
创建XML文档

        
向已存在的XML文档里添加数据 
    }

}

你可能感兴趣的:(add)