Пример #1
0
        //[ComVisible(true)]
        //public void Open()
        //{
        //    System.Windows.Forms.MessageBox.Show(Background);
        //}
        private void buttonTakeSnap_Click(object sender, EventArgs e)
        {
            int id;
            if (textBox1.Text.Length == 0 || !Int32.TryParse(textBox1.Text, out id))
            {
                if (sender == null)
                    (e as MeCompletedEventArgs).DataToReturn = "Please enter a valid ID";
                else
                    System.Windows.Forms.MessageBox.Show("Please enter a valid ID");

                return;
            }

            //if (id < 1 || id > 4)
            //{
            //    System.Windows.Forms.MessageBox.Show("only Ids 1,2,3,4 are allowed");
            //    return;
            //}

            buttonTakeSnap.Enabled = false;
            buttonGetPicture.Enabled = false;
            //button3.Enabled = false;
            //long length = MakeOneShot();

            //System.Diagnostics.Debugger.Break();

            String fileName = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + "\\rid50_pic.bmp";
            //String fileName = "c:\\temp\\rid50_pic.bmp";

            //new FileIOPermission(PermissionState.Unrestricted).Assert();
            TakeSnap(fileName);

            //IntPtr hWnd = pictureBox1.Handle;
            //StartPreview(hWnd);

            FileStream fs = null;
            MemoryStream ms = null;
            try
            {
                fs = new FileStream(fileName, FileMode.Open);
                BinaryReader br = new BinaryReader(fs);
                //MessageBox.Show("fs.Length : " + fs.Length);
                byte[] buffer = br.ReadBytes((int)fs.Length);
                fs.Close();
                //Image img = Image.FromStream(fs);

                ms = new MemoryStream(buffer);
                Image img = Image.FromStream(ms);

                pictureBox2.Image = img;

                //img.Save("c:\\aaa.jpg", ImageFormat.Jpeg);
                //MemoryStream mem = new MemoryStream();
                //img.Save(mem, System.Drawing.Imaging.ImageFormat.Jpeg);
                //byte[] buff = mem.ToArray();

                buttonTakeSnap.Focus();

                ms.Close();

                Bitmap bmp = new Bitmap(img);
                GrabImageClient.Helper.saveJpegToStream(out ms, bmp, 20L);
                //GrabImageClient.Helper.saveJpegToFile("c:\\temp\\kuku2.jpg", bmp, 20L);
                bmp.Dispose();

                buffer = ms.ToArray();

                //Bitmap bmp = new Bitmap(img);
                //Helper.saveJpegToStream(out ms, bmp, 50L);
                //bmp.Dispose();
                //img = Image.FromStream(ms);
                //img.Save("aaa50quality.jpg", ImageFormat.Jpeg);

                //Helper.saveJpeg("EMP_PICS.jpg", new Bitmap(img), 100L);

                //System.Diagnostics.Debugger.Break();
                //__debugbreak();

                //int mode = (int)SAVE.UPDATE;
                //if (String.IsNullOrEmpty(textBox1.Text))
                //    mode = (int)SAVE.INSERT;

                //var client = new WebServiceClient();
                //client.SetImage(id, ref buffer);

                IDataService client = null;

                IMAGE_TYPE imageType = IMAGE_TYPE.picture;
                if (GrabImageClient.Helper.getAppSetting("dbProvider") == "dedicatedServer")
                    client = new DbDataService();
                else if (GrabImageClient.Helper.getAppSetting("dbProvider") == "cloudServer")
                    client = new WebDataService();
                else
                    throw new Exception("Wrong database provider settings");

                //var client = new WebServiceClient();
                client.SendImage(imageType, id, ref buffer);

                //DBUtil db = new DBUtil();
                //db.SavePicture(VisitorsDatabase, mode, id, ref buffer);
                //textBox1.Text = db.SavePicture(VisitorsDatabase, mode, textBox1.Text, ref buffer);
                //System.Windows.Forms.MessageBox.Show("Id: " + id.ToString());
                //textBox1.Text = id.ToString();

                Thread.Sleep(2000);

                //buffer = db.GetPicure(1);

            }
            catch (Exception ex) {
                if (sender == null)
                    (e as MeCompletedEventArgs).DataToReturn = ex.Message;
                else
                    System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                //FileIOPermission.RevertAssert();
                fs.Close();
                ms.Close();
                if (retCode >= 0)
                    buttonTakeSnap.Enabled = true;

                buttonGetPicture.Enabled = true;
                //button3.Enabled = true;

                //File.Delete(fileName);
            }

            if (sender == null)
                (e as MeCompletedEventArgs).DataToReturn = "";
        }
Пример #2
0
        private void buttonGetPicture_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Background: " + Background);
            //this.BackColor = ColorTranslator.FromHtml(Background);

            int id;
            if (textBox1.Text.Length == 0 || !Int32.TryParse(textBox1.Text, out id))
            {
                if (sender == null)
                    (e as MeCompletedEventArgs).DataToReturn = "Please enter a valid ID";
                else
                    System.Windows.Forms.MessageBox.Show("Please enter a valid ID");

                return;
            }

            buttonTakeSnap.Enabled = false;
            buttonGetPicture.Enabled = false;
            //button3.Enabled = false;

            //String fileName = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache) + "\\rid50_pic.bmp";

            byte[] buffer = null;

            MemoryStream ms = null;
            IDataService client = null;

            IMAGE_TYPE imageType = IMAGE_TYPE.picture;

            try
            {
                if (GrabImageClient.Helper.getAppSetting("dbProvider") == "dedicatedServer")
                    client = new DbDataService();
                else if (GrabImageClient.Helper.getAppSetting("dbProvider") == "cloudServer")
                    client = new WebDataService();
                else
                    throw new Exception("Wrong database provider settings");

                buffer = client.GetImage(imageType, id);

                if (buffer == null)
                {
                    if (sender == null)
                        (e as MeCompletedEventArgs).DataToReturn = String.Format("No picture with Id '{0}' exists", textBox1.Text);
                    else
                        System.Windows.Forms.MessageBox.Show(String.Format("No picture with Id '{0}' exists", textBox1.Text));

                    return;
                }

                //MessageBox.Show(buffer.Length.ToString());
                ms = new MemoryStream(buffer);
                Image img = Image.FromStream(ms);

                pictureBox2.Image = img;

                buttonTakeSnap.Focus();

                ms.Close();
            }
            catch (Exception ex)
            {
                if (sender == null)
                    (e as MeCompletedEventArgs).DataToReturn = ex.Message;
                else
                    System.Windows.Forms.MessageBox.Show(ex.Message);

                return;
            }
            finally
            {
                if (ms != null)
                    ms.Close();

                if (retCode >= 0)
                    buttonTakeSnap.Enabled = true;

                buttonGetPicture.Enabled = true;
            }

            if (sender == null)
                (e as MeCompletedEventArgs).DataToReturn = "";
        }