Beispiel #1
0
        public ActionResult Barcode()
        {
            ConsumoWorker cWorker = new ConsumoWorker(Server.MapPath("~/"));

            var dealerships    = cWorker.GetDealerships();
            var dealershipJson = dealerships.Select(x => new { value = String.Concat(x.segment, x.code), label = x.dealership }).ToArray();

            ViewBag.dealerships = JsonConvert.SerializeObject(dealershipJson);

            return(View());
        }
        public JsonResult ByLine(string line)
        {
            if (!String.IsNullOrEmpty(line))
            {
                ByLineInfo lineJson = JsonConvert.DeserializeObject <ByLineInfo>(line);

                ExtraWorker   extra       = new ExtraWorker();
                CodebarResult extraResult = extra.GenerateBarcodeByLine(lineJson.fromLine);

                //+ 47 boleto
                if (extraResult.Line.Length == 47)
                {
                    int    bank  = Int32.Parse(extraResult.Line.Substring(0, 3));
                    string date  = extraResult.Line.Substring(33, 4);
                    string value = extraResult.Line.Substring(37, 10);

                    var _banks = BoletoWorker.GetBanks(Server.MapPath("~/")).Where(x => x.value == bank).FirstOrDefault();
                    lineJson.bank = _banks != null ? _banks.label : "";

                    lineJson.expirate = Utils.GetDateFromFactor(date).ToString("dd/MM/yyyy");
                    lineJson.value    = Utils.GetValueFormattedFromFactor(value);
                }
                //+ 48 conta de consumo
                else
                {
                    var    l       = extraResult.Line;
                    int    segment = Int32.Parse(l.Substring(1, 1));
                    string code    = l.Substring(16, 4);
                    string value   = string.Concat(l.Substring(4, 7), l.Substring(12, 4));

                    ConsumoWorker consumo = new ConsumoWorker(Server.MapPath("~/"));
                    var           _dealer = consumo.GetDealerships().Where(x => x.segment == segment && x.code == code).FirstOrDefault();
                    lineJson.dealership = _dealer != null ? _dealer.dealership : "";
                    lineJson.value      = Utils.GetValueFormattedFromFactor(value);
                }

                lineJson.line          = extraResult.Line;
                lineJson.lineFormatted = extraResult.LineFormatted;
                lineJson.barcodeBase64 = extraResult.BarcodeBase64;

                return(Json(JsonConvert.SerializeObject(lineJson)));
            }

            return(Json(null));
        }
Beispiel #3
0
        public JsonResult GenerateConsumo(string consumo)
        {
            if (!String.IsNullOrEmpty(consumo))
            {
                ConsumoInfo consumoJson = JsonConvert.DeserializeObject <ConsumoInfo>(consumo);

                ConsumoWorker cWorker = new ConsumoWorker(Server.MapPath("~/"));

                if (consumoJson.autoGenerate)
                {
                    DealershipInfo dealership = cWorker.RandomDealership();
                    consumoJson.segment = dealership.segment;
                    consumoJson.code    = dealership.code;

                    consumoJson.value = cWorker.RandomValue(consumoJson.valueStart, consumoJson.valueEnd);

                    CodebarResult consumoResult = cWorker.GenerateConsumo(consumoJson.segment, consumoJson.code, consumoJson.value.ToString());

                    consumoJson.line          = consumoResult.Line;
                    consumoJson.lineFormatted = consumoResult.LineFormatted;
                    consumoJson.barcodeBase64 = consumoResult.BarcodeBase64;

                    return(Json(JsonConvert.SerializeObject(consumoJson)));
                }
                else
                {
                    consumoJson.value = consumoJson.value.Replace(".", ",");
                    Double v;
                    Double.TryParse(consumoJson.value, out v);
                    consumoJson.value = v.ToString("N");

                    CodebarResult consumoResult = cWorker.GenerateConsumo(consumoJson.segment, consumoJson.code, consumoJson.value.ToString());

                    consumoJson.line          = consumoResult.Line;
                    consumoJson.lineFormatted = consumoResult.LineFormatted;
                    consumoJson.barcodeBase64 = consumoResult.BarcodeBase64;

                    return(Json(JsonConvert.SerializeObject(consumoJson)));
                }
            }

            return(Json(new { consumo = consumo }));
        }