Beispiel #1
0
        public void UploadUpcode(string filename)
        {
            int start = filename.LastIndexOf('\\') + 1;
            int end   = filename.LastIndexOf('.');
            var code  = filename.Substring(start, end - start);

            var  upc        = data.GetUpcodeByCode(code);
            bool existscode = upc != null;

            if (existscode && MessageBox.Show("El codigo " + code + " ya existe. \nDesea remplazarlo?", "Aviso", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            Bitmap bmpCrop = null;

            using (var im = Image.FromFile(filename) as Bitmap)
            {
                if (im == null)
                {
                    return;
                }
                if (im.Width == 300 && im.Height == 300)
                {
                    bmpCrop = im.Clone(new Rectangle(40, 0, 218, 256), PixelFormat.Undefined);
                }
            }
            if (bmpCrop != null)
            {
                bmpCrop.Save(filename, ImageFormat.Png);
            }

            byte[] img = File.ReadAllBytes(filename);

            if (!existscode)
            {
                upc = new upcode {
                    code = code
                }
            }
            ;
            upc.image = new Binary(img);
            if (!existscode)
            {
                data.AddUpcode(upc);
            }
        }
    }
Beispiel #2
0
 public void AddUpcode(upcode code)
 {
     dc.upcodes.InsertOnSubmit(code);
 }