using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;namespace FCXS.XS
{
/// <summary>
/// FrmPhoto 的摘要说明。
/// </summary>
public class FrmPhotoSetting : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pbx;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public FrmPhotoSetting()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.pbx = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// button3
//
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button3.Location = new System.Drawing.Point(200, 248);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(80, 24);
this.button3.TabIndex = 10;
this.button3.Text = "关闭";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Enabled = false;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(120, 248);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 24);
this.button2.TabIndex = 9;
this.button2.Text = "保存";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"正常",
"拉伸",
"自动",
"居中"});
this.comboBox1.Location = new System.Drawing.Point(208, 8);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 20);
this.comboBox1.TabIndex = 7;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(40, 248);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 6;
this.button1.Text = "打开图片";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(152, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 8;
this.label1.Text = "显示模式";
//
// comboBox2
//
this.comboBox2.Items.AddRange(new object[] {
"保留",
"出租",
"销售",
"预订",
"封房",
"待售"});
this.comboBox2.Location = new System.Drawing.Point(64, 8);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(80, 20);
this.comboBox2.TabIndex = 11;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 12;
this.label2.Text = "房产状态";
//
// pbx
//
this.pbx.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pbx.Location = new System.Drawing.Point(24, 40);
this.pbx.Name = "pbx";
this.pbx.Size = new System.Drawing.Size(264, 192);
this.pbx.TabIndex = 13;
this.pbx.TabStop = false;
//
// FrmPhotoSetting
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(312, 285);
this.Controls.Add(this.pbx);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.Name = "FrmPhotoSetting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "设置图片";
this.Load += new System.EventHandler(this.FrmPhoto_Load);
this.ResumeLayout(false); }
#endregion
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;namespace FCXS.XS
{
/// <summary>
/// FrmPhoto 的摘要说明。
/// </summary>
public class FrmPhotoSetting : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pbx;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public FrmPhotoSetting()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.pbx = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// button3
//
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button3.Location = new System.Drawing.Point(200, 248);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(80, 24);
this.button3.TabIndex = 10;
this.button3.Text = "关闭";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Enabled = false;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(120, 248);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(80, 24);
this.button2.TabIndex = 9;
this.button2.Text = "保存";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"正常",
"拉伸",
"自动",
"居中"});
this.comboBox1.Location = new System.Drawing.Point(208, 8);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(88, 20);
this.comboBox1.TabIndex = 7;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(40, 248);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(80, 24);
this.button1.TabIndex = 6;
this.button1.Text = "打开图片";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(152, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 16);
this.label1.TabIndex = 8;
this.label1.Text = "显示模式";
//
// comboBox2
//
this.comboBox2.Items.AddRange(new object[] {
"保留",
"出租",
"销售",
"预订",
"封房",
"待售"});
this.comboBox2.Location = new System.Drawing.Point(64, 8);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(80, 20);
this.comboBox2.TabIndex = 11;
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 12;
this.label2.Text = "房产状态";
//
// pbx
//
this.pbx.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.pbx.Location = new System.Drawing.Point(24, 40);
this.pbx.Name = "pbx";
this.pbx.Size = new System.Drawing.Size(264, 192);
this.pbx.TabIndex = 13;
this.pbx.TabStop = false;
//
// FrmPhotoSetting
//
this.AutoScale = false;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(312, 285);
this.Controls.Add(this.pbx);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.MaximizeBox = false;
this.Name = "FrmPhotoSetting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "设置图片";
this.Load += new System.EventHandler(this.FrmPhoto_Load);
this.ResumeLayout(false); }
#endregion
/// <summary>
/// 打开图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter ="位图文件(*.bmp)|*.bmp|jpg文件(*.jpg)|*.jpg|gif文件(*.gif)|*.gif|所有文件(*.*)|*.*";
ofd.FilterIndex =0;
if (ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
{
this.pbx.Image = Image.FromFile(ofd.FileName.ToString());
this.filename = ofd.FileName.ToString();
///保存按钮有效
this.button2.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} /// <summary>
/// 设置图片显示模式
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
switch (this.comboBox1.SelectedIndex)
{
case 0:
this.pbx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
break;
case 1:
this.pbx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
break;
case 2:
this.pbx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
break;
case 3:
this.pbx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage;
break;
default:
//this.pbx.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Normal;
break;
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
// MessageBox.Show(this.comboBox1.SelectedText);
} /// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
this.Close();
} private string filename ="";
public string updatesql ="update_xs_photo";
/// <summary>
/// 数据表名
/// </summary>
public string bh ="";
public string bh2 ="";
private System.Data.DataSet myds;
private System.Data.OleDb.OleDbDataAdapter myda;
private System.Windows.Forms.BindingManagerBase mybind; /// <summary>
/// 加载图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmPhoto_Load(object sender, System.EventArgs e)
{
myds = new DataSet();
myda = new OleDbDataAdapter("select p_bh,p_bz from photo",DB.OleConn());
myda.Fill(myds,"A"); mybind = this.BindingContext[myds,"A"]; this.comboBox2.DataSource = myds;
this.comboBox2.DisplayMember = "A.p_bz";
this.comboBox2.ValueMember = "A.p_bh"; this.mybind.PositionChanged += new EventHandler(this.Bindpositiochange1);
} private void Bindpositiochange1(object sender, System.EventArgs e)
{
try
{
string lb = "";
if (myds.Tables["A"].Rows.Count>0)
{
lb = myds.Tables["A"].Rows[mybind.Position]["p_bh"].ToString();
this.loadImage("select p_photo from photo where p_bh ='"+lb+"' ");
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} private void loadImage( string sql )
{
byte[] buffByte = null;
try
{
System.Data.OleDb.OleDbCommand mycmd = new System.Data.OleDb.OleDbCommand(sql,DB.OleConn());
if (mycmd.Connection.State != System.Data.ConnectionState.Open)
{
mycmd.Connection.Open();
}
System.Data.OleDb.OleDbDataReader myrd = mycmd.ExecuteReader();
if(myrd.HasRows)
{
myrd.Read();
buffByte = ((byte[])myrd[0]);
//将图像的字节数组放入内存流
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffByte);
//通过流对象建立Bitmap
System.Drawing.Bitmap bmp = new Bitmap(ms);
this.pbx.Image = bmp;
}
else
{
this.pbx.Image = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message+",图片不存在!");
}
finally
{
}
} /// <summary>
/// 保存图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, System.EventArgs e)
{
try
{
System.IO.FileInfo fs = new System.IO.FileInfo(this.filename);
if (!fs.Exists)
{
MessageBox.Show("无效的文件名!");
return;
}
//创建一字节数组,用来存储图像文件.(数组的长度是图像文件的长度)
byte[] Content=new byte[fs.Length];
//打开文件并用他初始化一个文件流对象
FileStream ImageFileStream=fs.OpenRead();
//将文件内容写入字节数组
ImageFileStream.Read(Content,0,Content.Length);
//关闭文件流
ImageFileStream.Close(); //创建一个Sql命令对象,用来插入记录
System.Data.OleDb.OleDbCommand mycmd = new System.Data.OleDb.OleDbCommand(updatesql,DB.OleConn());
mycmd.CommandType = CommandType.StoredProcedure;
mycmd.Parameters.Add("@image",System.Data.OleDb.OleDbType.VarBinary);
mycmd.Parameters.Add("@bh",OleDbType.VarChar,20); mycmd.Parameters["@image"].Value = Content;
mycmd.Parameters["@bh"].Value = myds.Tables["A"].Rows[mybind.Position]["p_bh"].ToString();
//打开数据库连接
if (mycmd.Connection.State!=ConnectionState.Open)
{
mycmd.Connection.Open();
}
//执行 Sql 语句
mycmd.ExecuteNonQuery();
//关闭数据库连接
mycmd.Connection.Close(); MessageBox.Show("图像文件 " + fs.FullName + " 成功上传到数据库!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
If files.PostedFile.ContentLength = 0 Then
Result.Text = "上传失败或指定的文件不存在"
FileInfo.Visible = False
Else
'获取文件名称
Dim Route() As String = Split(files.PostedFile.FileName, "\")
Dim FileName As String = Route(Route.Length - 1) '保存文件
files.PostedFile.SaveAs(Server.MapPath(".") & "\uploadfiles\" & FileName)
''''''''''''''''显示上传结果" order by date2 desc"
FileInfo.Visible = True
Result.Text = "上传成功"
FName.Text = FileName
FSize.Text = Math.Round(files.PostedFile.ContentLength / 1024, 2) & "KB"
FType.Text = files.PostedFile.ContentType
savepath.Text = "<a href=uploadfiles/"& FileName &">点击下载</a>"
End If
End SubSub AddRecord(sender As Object, e As EventArgs)
Dim objConn As New OleDbConnection()
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("upload.mdb")
objConn.Open()
Dim strSQL As String
strSQL = "Insert Into upload(files)" & " Values ( '" & savepath.Text & "')"
Dim objCmd As New OleDbCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
objConn.Close()
End Sub</Script>
<Form Runat="Server" Enctype="multipart/form-data">
<center>写邮件</center>
<Table Border="1" Width="500" Align="Center" Cellspacing="0"><Td Width="80">附件:</Td>
<Td Width="520">
<Center>
文件位置:
<Input Type="File" Runat="Server" Id="files" Size="50"><Br><Br>
<Asp:Button Runat="Server" Text="上传" OnClick="Upload" />
<Input Type="Reset" Value="重新设置">
<Hr><H1><Asp:Label Runat="Server" Id="Result"/></H1>
</Center>
<Asp:Panel Runat="Server" Id="FileInfo" Visible="False">
文件名称:<Asp:Label Runat="Server" Id="FName" /><Br>
文件大小:<Asp:Label Runat="Server" Id="FSize" /><Br>
文件类型:<Asp:Label Runat="Server" Id="FType" /><Br>
保存路径: <asp:label runat="Server" Id="savepath" /><br>
</Asp:Panel>
</Td>
<Tr>
<Td Colspan="2" Align="Center">
<Asp:LinkButton Runat="Server" Text="保存" OnClick="AddRecord" />
</Td>
</Tr>
</Table>
</form>*******************************************
数据库自己写。
ACCESS的。
' / .- .
. .- .-
./ .--...
.-------- 0 .--
/ .......
' ..
'........ ----
. --..
. .---.. -
分 o . ' -.
分 / '
/ ' ' '
\-分--/....... . ' ' ' '
\ __/ - - -' ' ' '
' ' ' '
o ' ' ' '
' ' '
-..'.----------.
I ----------
/////////.