ویژوال 30 شارپ

سورس کدهای جالب سی شارپ فقط با یک نگاه

ویژوال 30 شارپ

سورس کدهای جالب سی شارپ فقط با یک نگاه

نمایش حجم درایو

کدی که امروز خدمتتان آوردم حجم درایو انتخاب شده رو به شکل یک نمودار دایره ای نشان می دهد.

دانلود کنید که واقعا قشنگه (آسون هم هست).


http://s1.picofile.com/file/6123690140/DriveSizeViewer.mp3.html

کد سی شارپ (همراه با توضیح انگلیسی)

در این پست می خوام مجموعه ای از کد های سی شارپ با توضیحات انگلیسی را خدمت شما تقدیم کنم.

ادامه مطلب ...

ذخیره کردن عکس با فرمت دلخواه!

این کد عکس داخل pictureBox رو به فرمت دلخواه (که در اینجا Jpeg) ذخیره می کنه. 

SaveFileDialog saveFileDlg = New SaveFileDialog();

if (saveFileDlg.ShowDialog() == DialogResult.OK)

try
{

Bitmap bMP = (Bitmap)this.pictureBox1.Image;

bMP.Save(saveFileDlg.FileName,System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch {}

ذخیره و بازیابی عکس در اس کیو ال

اول عکس رو لود می کنیم : 

 

protected void LoadImage()
{
    try
    {
        this.openFileDialog1.ShowDialog(this);
        string strFn=this.openFileDialog1.FileName;
        this.pictureBox1.Image=Image.FromFile(strFn);
        FileInfo fiImage=new FileInfo(strFn);
        this.m_lImageFileLength=fiImage.Length;
        FileStream fs=new FileStream(strFn,FileMode.Open,
                          FileAccess.Read,FileShare.Read);
        m_barrImg=new byte[Convert.ToInt32(this.m_lImageFileLength)];
        int iBytesRead = fs.Read(m_barrImg,0,
                         Convert.ToInt32(this.m_lImageFileLength));
        fs.Close();
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

 

عملیات ثبت : 

  private void btnSave_Click(object sender, System.EventArgs e)
{
    try
    {
        this.sqlConnection1.Open();
        if (sqlCommand1.Parameters.Count ==0 )
        {
            this.sqlCommand1.CommandText="INSERT INTO tblImgData(ID," +
                           " Name,Picture) values(@ID,@Name,@Picture)";
            this.sqlCommand1.Parameters.Add("@ID",
                             System.Data.SqlDbType.Int,4);
            this.sqlCommand1.Parameters.Add("@Name",
                             System.Data.SqlDbType.VarChar,50);
            this.sqlCommand1.Parameters.Add("@Picture",
                             System.Data.SqlDbType.Image);
        }

        this.sqlCommand1.Parameters["@ID"].Value=this.editID.Text;
        this.sqlCommand1.Parameters["@Name"].Value=this.editName.Text;
        this.sqlCommand1.Parameters["@Picture"].Value=this.m_barrImg;

        int iresult=this.sqlCommand1.ExecuteNonQuery();
        MessageBox.Show(Convert.ToString(iresult));
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        this.sqlConnection1.Close();
    }

 

کد بازیابی :  

private void btnLoad_Click(object sender, System.EventArgs e)
{
    try
    {
        SqlCommand cmdSelect=new SqlCommand("select Picture" +
              " from tblImgData where ID=@ID",this.sqlConnection1);
        cmdSelect.Parameters.Add("@ID",SqlDbType.Int,4);
        cmdSelect.Parameters["@ID"].Value=this.editID.Text;

        this.sqlConnection1.Open();
        byte[] barrImg=(byte[])cmdSelect.ExecuteScalar();
        string strfn=Convert.ToString(DateTime.Now.ToFileTime());
        FileStream fs=new FileStream(strfn,
                          FileMode.CreateNew, FileAccess.Write);
        fs.Write(barrImg,0,barrImg.Length);
        fs.Flush();
        fs.Close();
        pictureBox1.Image=Image.FromFile(strfn);
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
        this.sqlConnection1.Close();
    }

امید وارم فهمیده باشید.