Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Helper.Exists("users", "name", nameTxtBx.Text))
            {
                MessageBox.Show("User name exists");
                return;
            }
            if (Helper.Exists("users", "contact", contactTxtBx.Text))
            {
                MessageBox.Show("User contact exists");
                return;
            }
            string userID = Guid.NewGuid().ToString();
            string paths  = @"c:\Case\images";

            if (!Directory.Exists(paths))
            {
                DirectoryInfo dim = Directory.CreateDirectory(paths);
                Console.WriteLine("The directory was created successfully at {0}.",
                                  Directory.GetCreationTime(paths));
            }

            string     filename = @"c:\Case\\images\" + userID.Trim() + ".jpg";
            FileStream fstream  = new FileStream(filename, FileMode.Create);

            imgCapture.Image.Save(fstream, System.Drawing.Imaging.ImageFormat.Jpeg);
            fstream.Close();


            string image = @"c:\Case\\images\" + userID.Trim() + ".jpg";

            if (System.IO.File.Exists(image))
            {
                try
                {
                    string filepath   = image;
                    string localPath  = new Uri(filepath).LocalPath;
                    string remotePath = Helper.uploadUrl;

                    WebClient theClient     = new WebClient();
                    byte[]    responseArray = theClient.UploadFile(remotePath, filepath);
                    Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}", System.Text.Encoding.ASCII.GetString(responseArray));
                    theClient.Dispose();
                }
                catch (Exception c)
                {
                }
            }

            try
            {
                string Query = "INSERT INTO users(userID, orgID, name, email, password, designation, status, contact, image, address, category, created, sync, charge, supervisor) VALUES ('" + userID + "','" + Helper.orgID + "','" + this.nameTxtBx.Text + "','" + this.emailTxtBx.Text + "','" + Helper.MD5Hash(this.passwordTxtBx.Text) + "','" + this.designationCbx.Text + "','" + this.statusCbx.Text + "','" + this.contactTxtBx.Text + "','" + userID.Trim() + ".jpg" + "','" + this.addressTxtBx.Text + "','staff','" + DateTime.Now.Date.ToString("yyyy-MM-dd") + "','f','" + this.chargeTxtBx.Text + "','" + supervisorCbx.Text + "');";
                Helper.Execute(Query, DBConnect.conn);
                MessageBox.Show("Information saved");
                UserForm frm = new UserForm();
                frm.MdiParent = MainForm.ActiveForm;
                frm.Show();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }