Beispiel #1
0
        private void combo1change(object sender, EventArgs e)
        {
            type = comboBox1.SelectedValue.ToString();
            if (type.Equals("未知"))
            {
                labeltextchange();
            }
            else
            {
                BLL bll = new BLL();
                DataTable dt = bll.uperrestrictedbytype(type);
                dt.Columns[0].ColumnName = "uper";
                DataRow dr = dt.NewRow();
                dr["uper"] = "未知";
                dt.Rows.Add(dr);

                comboBox2.DataSource = dt;
                comboBox2.DisplayMember = "uper";
                comboBox2.ValueMember = "uper";
                comboBox2.SelectedIndex = dt.Rows.Count - 1;

                DataTable dt2 = bll.titlerestrictedbytype(type);
                dt2.Columns[0].ColumnName = "title";
                comboBox3.DataSource = dt2;
                comboBox3.DisplayMember = "title";
                comboBox3.ValueMember = "title";
            }
        }
Beispiel #2
0
        private void goregist(object sender, EventArgs e)
        {
            BLL bll=new BLL();
            string name,pass1;
            label5.Text = "";
            label6.Text = "";
            label7.Text = "";

            if (textBox1.Text == null)
            {
                label5.Text = "用户名不能为空";
                return;
            }
            else
            {
                name=textBox1.Text.ToString();
                pass1="";

                if(bll.checkuser(name,pass1)!=2)
                {
                    label5.Text = "用户名已被占用";
                    return;
                }
            }
            if (textBox2.Text == null)
            {
                label6.Text = "密码不能为空";
                return;
            }
            else if (textBox2.Text.ToString().Length < 6)
            {
                label6.Text = "密码长度不能小于6个字符";
                return;
            }
            else if (!(textBox2.Text.ToString().Equals(textBox3.Text.ToString())))
            {
                label7.Text = "两次输入的密码不一致";
                return;
            }
            else
            {
                pass1 = textBox2.Text.ToString();
                bll.insertcustomer(bll.maxid(false)+1, name, pass1);
                MessageBox.Show("注册成功!");
                this.Close();

                login log = (login)this.Owner;
                log.Show();
            }
        }
Beispiel #3
0
        public Form3()
        {
            InitializeComponent();

            BLL bll = new BLL();

            DataTable dt1 = bll.showtype();

            dt1.Columns[0].ColumnName = "type";
            DataRow dr1 = dt1.NewRow();
            dr1["type"] = "未知";
            dt1.Rows.Add(dr1);

            comboBox1.DataSource = dt1;
            comboBox1.DisplayMember = "type";
            comboBox1.ValueMember = "type";
            comboBox1.SelectedIndex = dt1.Rows.Count-1;
            //comboBox1.Items.Add("未知");
            //comboBox1.Items.Insert(0, "unkown");

            type = comboBox1.SelectedValue.ToString();

            DataTable dt2 = bll.showuper();
            dt2.Columns[0].ColumnName = "uper";
            DataRow dr2 = dt2.NewRow();
            dr2["uper"] = "未知";
            dt2.Rows.Add(dr2);

            comboBox2.DataSource = dt2;
            comboBox2.DisplayMember = "uper";
            comboBox2.ValueMember = "uper";
            comboBox2.SelectedIndex = dt2.Rows.Count - 1;

            uper = comboBox2.SelectedValue.ToString();

            DataTable dt3 = bll.showtitle();
            dt3.Columns[0].ColumnName = "title";

            comboBox3.DataSource = dt3;
            comboBox3.DisplayMember = "title";
            comboBox3.ValueMember   = "title";

            title = comboBox3.SelectedValue.ToString();
            label4.Text = "(您要下载的是\n   主题为  :" + comboBox1.SelectedValue.ToString() +
                        "\n   上传者为:" + comboBox2.SelectedValue.ToString() +
                        "\n   文章名为:" + comboBox3.SelectedValue.ToString() + "\n的资料!)";
        }
Beispiel #4
0
        private void upload(object sender, EventArgs e)
        {
            string labelname="";
            string onlyfile="";
            string uristring;
            string path;
            string i = textBox1.Text.ToString();
            if (textBox1.Text.ToString() == "")
            {
                MessageBox.Show("请输入要上传的文件!");
                return;
            }

            if (textBox2.Visible == false)
            {
                labelname = comboBox1.SelectedValue.ToString();
            }
            else if (textBox2.Text.ToString() == "")
            {
                MessageBox.Show("新创建的主题名不能为空哦!");
                return;
            }
            else
                labelname = textBox2.Text;

            onlyfile = fileName.Substring(fileName.LastIndexOf("\\") + 1);
            uristring = "f:\\databaseupdown\\" + labelname + "\\" +onlyfile;
            string p = uristring.Replace("\\", "/");

            path = "f:\\databaseupdown\\" + labelname;

            WebClient myWebClient = new WebClient();
            //设置应用程序的系统凭据
            myWebClient.Credentials = CredentialCache.DefaultCredentials;
            //要上传的文件穿件文件流
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
            //以二进制方式读取
            BinaryReader br = new BinaryReader(fs);
            //当前流写入二进制
            byte[] postArray = br.ReadBytes((int)fs.Length);

            Stream postStream = myWebClient.OpenWrite(uristring,"PUT");
            try
            {
                if (postStream.CanWrite)
                {
                    postStream.Write(postArray, 0, postArray.Length);
                    postStream.Close();
                    fs.Dispose();
                    BLL bll = new BLL();
                    int id=bll.maxid(true)+1;
                    DateTime dt=DateTime.Now;
                    //暂且先用new用户的身份插入数值
                    //通过theruserid传值,来用登陆者身份插入数值
                    bll.insertfile(id, onlyfile, labelname, dt, theuserid2, p);
                    MessageBox.Show("上传成功");
                }
                else
                {
                    postStream.Close();
                    fs.Dispose();
                    MessageBox.Show("上传失败");
                }
            }
            catch (Exception ex)
            {

                postStream.Close();
                fs.Dispose();
                MessageBox.Show("上传文件异常" + ex.Message);
                throw ex;
            }
            finally
            {
                postStream.Close();
                fs.Dispose();
            }
        }
Beispiel #5
0
        private void download(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            save.ShowDialog();

            BLL bll=new BLL();
            //string URL = "f:\\databaseupdown\\" + type + "\\" + title;
            string p = bll.getpath(title, type, uper);

            if (p.Equals(""))
            {
                MessageBox.Show("数据库中未提供路径!");
                return;
            }

            string URL = p.Replace("/","\\");
            string path = save.FileName;
            string onlyfilename = path.Substring(path.LastIndexOf("\\") + 1);

            WebClient client = new WebClient();

            try
            {
                WebRequest myRe = WebRequest.Create(URL);

            }
            catch (Exception ex)
            {
                MessageBox.Show("下载文件异常" + ex.Message);
            }
            try
            {
                client.DownloadFile(URL, onlyfilename);
                FileStream fs = new FileStream(onlyfilename, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                int length = (int)fs.Length;
                byte[] mybyte = br.ReadBytes(length);
                Thread.Sleep(2000);
                fs.Close();
                //进程占用出现在这里,访问不了文件
                //FileStream fc = File.Create(path);
                //fc.Close();
                FileStream fstm = new FileStream(path, FileMode.Create, FileAccess.Write);

                fstm.Write(mybyte, 0, length);
                fstm.Close();
                MessageBox.Show("下载文件成功!");
            }
            catch (Exception ex)
            {

                MessageBox.Show("下载文件异常" + ex.Message);
            }
        }
Beispiel #6
0
 private void combo2change(object sender, EventArgs e)
 {
     uper = comboBox2.SelectedValue.ToString();
     if (uper.Equals("未知"))
     {
         labeltextchange();
     }
     else
     {
         BLL bll = new BLL();
         DataTable dt = bll.titlerestrictedbytypeuper(type,uper);
         dt.Columns[0].ColumnName = "title";
         comboBox3.DataSource = dt;
         comboBox3.DisplayMember = "title";
         comboBox3.ValueMember = "title";
     }
 }