⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form6.cs

📁 用VS2008写的配件管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace PeiJian
{
    public partial class Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }

        data data = new data();
        int a = 0, b = 0;
        private OleDbDataReader reader;
        public string text2;
        public void tjmingcheng()
        {
            int rows = 0;
            string sqlstr = "insert into dianlutu(mingcheng) values('" + text2 + "')";
            try
            {
                rows = data.Operdata(sqlstr);
            }

            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
        public void canshu()
        {
            string sqlstr = "select * from dianlutu where mingcheng='" + text2 + "'";
            reader = data.GetData(sqlstr);

            while (reader.Read())
            {
                if (reader["beizhu"].ToString() != "")
                {
                    textBox2.Text = reader["beizhu"].ToString();
                    b = 1;
                }
                else
                    b = 0;
                if (reader["dianlutu"].ToString() != "")
                {
                    string MyFileName = string.Empty;
                    MyFileName = reader["dianlutu"].ToString();
                    pictureBox1.Image = Image.FromFile(MyFileName);
                    this.hScrollBar1.Maximum = this.pictureBox1.Width - panel1.Width + vScrollBar1.Width;
                    this.vScrollBar1.Maximum = this.pictureBox1.Height - panel1.Height + hScrollBar1.Height;
                    a = 1;
                }
                else
                    a = 0;
            }

            reader.Close();
        }
        public void tj()
        {
            int rows = 0;
            string sqlstr = "update dianlutu set dianlutu='" + saveFileDialog1.FileName + "'where mingcheng='" + text2 + "'";
            try
            {
                rows = data.Operdata(sqlstr);

                if (rows != 1)
                {
                    MessageBox.Show("没有添加成功");
                }
                else
                {
                    MessageBox.Show("恭喜您,添加成功!");
                }

            }

            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
        public void tjcanshu()
        {
            int rows = 0;
            string sqlstr = "update dianlutu set beizhu='" + textBox2.Text + "' where mingcheng='" + text2 + "'";
            try
            {
                rows = data.Operdata(sqlstr);

                if (rows != 1)
                {
                    MessageBox.Show("没有成功");
                }
                else
                {
                    MessageBox.Show("恭喜您,成功!");
                }

            }

            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
        public void have()
        {
            string sqlstr = "select * from dianlutu where mingcheng='" + text2 + "'";
            reader = data.GetData(sqlstr);

            if (reader.Read() == false)
            {
                reader.Close();
                tjmingcheng();
            }
            reader.Close();
        }
        public void shanchu()
        {
            int rows = 0;
            string sqlstr = "delete from dianlutu where mingcheng='" + text2 + "'";
            try
            {
                rows = data.Operdata(sqlstr);

                if (rows != 1)
                {
                    MessageBox.Show("没有成功");
                }
                else
                {
                    MessageBox.Show("恭喜您,成功!");
                }

            }

            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                openFileDialog1.Title = "打开图片";
                openFileDialog1.Filter = "所有图像文件(JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg; *.gif;*.bmp;*.tif; *.tiff; *.png| JPeg图像文件(*.jpg;*.jpeg) |*.jpg;*.jpeg |GIF图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)| *.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*";
                openFileDialog1.Multiselect = false;
                openFileDialog1.FilterIndex = 1;
                openFileDialog1.RestoreDirectory = false;
                openFileDialog1.InitialDirectory = "c:\\";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string MyFileName = openFileDialog1.FileName;
                    pictureBox1.Image = Image.FromFile(MyFileName);
                    this.hScrollBar1.Maximum = this.pictureBox1.Width - panel1.Width + vScrollBar1.Width;
                    this.vScrollBar1.Maximum = this.pictureBox1.Height - panel1.Height + hScrollBar1.Height;
                }
                else
                {
                    return;
                }
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Title = "上传图片";
            saveFileDialog1.Filter = "所有JPG图像文件(*.jpg)|*.jpg";
            if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
                return;
            try
            {
                Image MyImage = pictureBox1.Image;
                string MyFileName = saveFileDialog1.FileName;
                pictureBox1.Image.Save(MyFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                if (saveFileDialog1.FileName != "")
                {
                    tj();
                    canshu();
                    if (a == 1)
                    {
                        button1.Enabled = false;
                        button2.Enabled = false;
                        button6.Enabled = false;
                        button8.Enabled = false;
                    }
                }
                else
                {
                    MessageBox.Show("路径错误!");
                }
            }
            catch (Exception MyEx)
            {
                MessageBox.Show(MyEx.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }  
        }

        private void button4_Click(object sender, EventArgs e)
        {
            textBox2.ReadOnly = false;
            button6.Enabled = true;
            button8.Enabled = true;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox2.ReadOnly = false;
            button6.Enabled = true;
            button8.Enabled = true;
            button1.Enabled = true;
            button2.Enabled = true;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            shanchu();
            this.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            tjcanshu();
            button4.Enabled = false;
            button6.Enabled = false;
            button8.Enabled = false;
            textBox2.ReadOnly = true;
            button3.Enabled = true;
        }

        private void button8_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            button2.Enabled = false;
            button6.Enabled = false;
            button8.Enabled = false;
            textBox2.ReadOnly = true;
            canshu();
        }

        private void Form6_Load(object sender, EventArgs e)
        {
            openFileDialog1.FileName = "";
            saveFileDialog1.FileName = "";
            textBox1.Text = text2;
            have();
            canshu();
            if (a == 1)
            {
                button1.Enabled = false;
                button2.Enabled = false;
            }
            if (b == 0)
            {
                button3.Enabled = false;
            }
            if (b == 1)
            {
                button3.Enabled = true;
                button4.Enabled = false;
            }
            button6.Enabled = false;
            button8.Enabled = false;
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            this.pictureBox1.Left = -this.hScrollBar1.Value;
        }

        private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            this.pictureBox1.Top = -this.vScrollBar1.Value;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -