Esempio n. 1
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();
            }
        }
Esempio n. 2
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();
            }
        }