救急~~~~~~~~,请高手帮忙!

bluefeilin 2006-10-30 08:40:59
问大家这样一个问题:
我上传图片的时候,是把图片保存在一个文件夹下的,把它的路径存在数据库中的,现在我要做后台,在删除该图片的路径的同时也要删除文件夹下相对应的图片.求源代码.
...全文
87 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
N_ccw 2006-11-01
  • 打赏
  • 举报
回复
在使用的时候当然不能删
song530061187 2006-11-01
  • 打赏
  • 举报
回复
System.IO.File.Delete(文件路径字符串) 我在弄 ,可是出错,说正在使用图片,不能删除。。 郁闷啊。


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace MapDeleteAndSql
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class main : System.Windows.Forms.Form
{
private static int i = 1;
private static int g = 1;
private static string str;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public main()
{
//
// 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.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(16, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(280, 184);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(16, 224);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 32);
this.button1.TabIndex = 1;
this.button1.Text = "上一张";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 224);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(64, 32);
this.button2.TabIndex = 2;
this.button2.Text = "一下张";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(216, 224);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(64, 32);
this.button3.TabIndex = 3;
this.button3.Text = "删除";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// main
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
this.ClientSize = new System.Drawing.Size(312, 278);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "main";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "删除SQL中的图片";
this.Load += new System.EventHandler(this.main_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new main());
}

private void main_Load(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("server = (local);Integrated Security = SSPI; Database = song;");
SqlCommand comm = new SqlCommand("SELECT path FROM map",conn);
try
{
conn.Open();
SqlDataReader thisReader = comm.ExecuteReader();
thisReader.Read();
str = thisReader[0].ToString();
this.pictureBox1.Image=Image.FromFile(thisReader[0].ToString());
while ( thisReader.Read() )
{
g+=1;
}
thisReader.Close();
//MessageBox.Show(g.ToString());
}
catch( SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
private void Showmap(int i)
{
if ( i >= 0 )
{
SqlConnection conn = new SqlConnection("server = (local);Integrated Security = SSPI; Database = song;");
SqlCommand comm = new SqlCommand("SELECT path FROM map",conn);
try
{
conn.Open();
SqlDataReader thisReader = comm.ExecuteReader();
int k = 0;
while( thisReader.Read() )
{
k++;
if ( k == i)
{
str = thisReader.GetString(0);
//MessageBox.Show(str);
this.pictureBox1.Image=Image.FromFile(str);
break;
}
}
}
catch( SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
}
}
private void button1_Click(object sender, System.EventArgs e)
{
if ( i> 1 )
{
i-=1;
//MessageBox.Show(i.ToString());
Showmap(i);
}
}

private void button2_Click(object sender, System.EventArgs e)
{
if ( i < g )
{
i+=1;
//MessageBox.Show(i.ToString());
Showmap(i);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
SqlConnection conn = new SqlConnection("server = (local);Integrated Security = SSPI; Database = song;");
//MessageBox.Show(str);
string ss = "DELETE FROM map WHERE path="+str.Trim().ToString();
MessageBox.Show(ss.ToString());
SqlCommand comm = new SqlCommand(ss,conn);
try
{
conn.Open();
//comm.ExecuteNonQuery();
g--;
}
catch( SqlException ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
conn.Close();
}
if( g > 0 )
{

if ( i < g )
{
i+=1;
//MessageBox.Show(i.ToString());
Showmap(i);
}


}
System.IO.File.Delete(str);
}



}
}


刚刚学习 .NET 学得乱七八糟 请大家多多指教。。。
大选 2006-11-01
  • 打赏
  • 举报
回复
幫忙頂
内容概要:本文围绕“面向高精度电流控制的PMSM多参数PSO辨识模型研究”,系统阐述了基于Simulink的永磁同步电机(PMSM)多参数辨识方法,重点采用粒子群优化算法(PSO)实现对电机关键内部参数的高精度辨识。研究构建了完整的PMSM控制系统仿真模型,结合智能优化算法,解决了传统参数辨识中精度低、收敛慢的问题,有效提升了电流环控制的动态性能与稳态精度。该方法特别适用于对控制精度和响应速度要求较高的工业应用场景,如高性能伺服系统、电动汽车驱动系统等,具有较强的工程实用价值和科研参考意义。文中提供了完整的Simulink仿真模型与配套代码,确保了研究内容的可复现性和实践操作性。; 适合人群:具备电机控制、自动化或电气工程等相关专业背景,熟悉MATLAB/Simulink仿真环境,从事电机驱动系统研发、控制算法设计或相关领域科研工作的工程师及研究生,尤其适合工作1-5年、希望深入理解先进参数辨识技术的研发人员。; 使用场景及目标:①开展高精度PMSM控制系统的设计与参数辨识研究;②学习并掌握PSO等智能优化算法在电机系统参数辨识中的具体实现与调优技巧;③完成学术论文复现、科研项目验证、毕业设计或工程原型开发,提升对现代电机控制核心技术的理解与应用能力。; 阅读建议:建议读者结合提供的Simulink模型与源代码进行动手实践,按照文档逻辑逐步搭建与调试仿真系统,重点关注PSO算法与电机模型的交互机制、目标函数设计及参数收敛过程,通过对比不同工况下的辨识结果,深入理解算法性能与控制精度之间的内在联系。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧