public ActionResult Result()
        {
            string decoded = DecodeCapturedPhoto();

            if (decoded == "")
            {
                return(View("Error"));
            }

            BarCode barcode = BarCode.GetData(decoded);

            if (!barcode.valid)
            {
                ViewBag.QrResult = barcode.code + " are un format invalid";
            }
            else
            if (!CheckIfRecordExists(barcode.code, barcode.quantity))
            {
                ViewBag.QrResult = barcode.code + " nu a putut fi gasit in baza de date";
            }
            else
            if (!DeleteEntry(barcode.code, barcode.quantity))
            {
                ViewBag.QrResult = barcode.code + " nu a putut fi sters din baza de date";
            }
            else
            {
                ViewBag.QrResult = barcode.code + " " + barcode.quantity + " a fost sters din baza de date";
            }

            return(View());
        }
Esempio n. 2
0
        private void Encode(BarCode data)
        {
            MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
            encoder.QRCodeScale = 10;

            var   bitmap         = encoder.Encode(data.code + " " + data.quantity);
            Image generatedImage = (Image)bitmap;

            string currentTime = DateTime.Now.Year.ToString() + "." + DateTime.Now.Month.ToString() + "." + DateTime.Now.Day.ToString() + " " +
                                 DateTime.Now.Hour.ToString() + "." + DateTime.Now.Minute.ToString() + "." + DateTime.Now.Second.ToString();

            generatedImage.Save(Server.MapPath("~/GeneratedImages/generated_qr" + currentTime + ".jpg"), System.Drawing.Imaging.ImageFormat.Jpeg);
            ViewBag.GeneratedQrImagePath = "~/GeneratedImages/generated_qr" + currentTime + ".jpg";
        }
Esempio n. 3
0
        private bool SqlValid(BarCode data)
        {
            string dbCommand = "";

            if (!CheckIfRecordExists(data.code))
            {
                dbCommand = "INSERT INTO Produse VALUES('" + data.code + "', '" + data.quantity.ToString() + "')";
            }

            if (!ExecuteDbCommand(dbCommand))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        // GET: DataBase
        public ActionResult Index()
        {
            try
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                con.Open();


                var        model = new List <BarCode>();
                SqlCommand cmd   = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT * FROM Produse";
                cmd.ExecuteNonQuery();

                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    BarCode bc = new BarCode("", 0);
                    bc.id       = int.Parse(rdr["Id"].ToString());
                    bc.code     = rdr["codProdus"].ToString();
                    bc.quantity = int.Parse(rdr["cantitate"].ToString());

                    model.Add(bc);
                }
                ViewBag.List = model;

                con.Close();
            }
            catch
            {
                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                return(View("Error"));
            }

            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }

            return(View());
        }
Esempio n. 5
0
        public ActionResult Index(string barcode)
        {
            BarCode codeData = BarCode.GetData(barcode);

            if (!codeData.valid || codeData.quantity <= 0)
            {
                return(View("Error"));
            }

            if (!SqlValid(codeData))
            {
                return(View("Error"));
            }
            Encode(codeData);
            DecodeGeneratedCodes();

            return(View());
        }
Esempio n. 6
0
        public static BarCode GetData(string barcode)
        {
            BarCode generatedCode = new BarCode(barcode, 0, false);

            if (barcode.Split(' ').Length != 2)
            {
                return(generatedCode);
            }

            try
            {
                string code     = barcode.Split(' ')[0];
                int    quantity = int.Parse(barcode.Split(' ')[1]);

                generatedCode.code     = code;
                generatedCode.quantity = quantity;
                generatedCode.valid    = true;
            }
            catch
            {
                return(generatedCode);
            }
            return(generatedCode);
        }