public ActionResult addVoucherProduct()
        {
            System.Diagnostics.Debug.WriteLine("them voucher product");
            int voucherId = Convert.ToInt32(Request.Form["voucherId"]);

            System.Diagnostics.Debug.WriteLine("voucher id" + voucherId);

            voucher v = new voucher {
                id = voucherId
            };

            db.vouchers.Add(v);
            db.vouchers.Attach(v);

            List <Product> products = Session["productVoucher" + voucherId] as List <Product>;
            product        product;

            foreach (Product pro in products)
            {
                product = new product {
                    id = pro.id
                };
                db.products.Add(product);
                db.products.Attach(product);
                v.products.Add(product);
                db.SaveChanges();
            }

            Session.Remove("productVoucher" + voucherId);
            return(RedirectToAction("voucherList", "Voucher"));
        }
        public async Task <IHttpActionResult> buyBulkVoucher(int userID, decimal BulkVoucherAmount)
        {
            if (isUserReseller(userID))
            {
                //need to check if reseller has the available funds in bank account - else return bad request or err page
                //transfer money from reseller bank account to nanoFin account

                voucher newVoucher = new voucher();
                newVoucher.User_ID             = userID;
                newVoucher.voucherValue        = BulkVoucherAmount;
                newVoucher.VoucherType_ID      = 1;
                newVoucher.voucherCreationDate = DateTime.Now;
                db.vouchers.Add(newVoucher);
                db.SaveChanges();

                addVoucherTransaction(newVoucher.Voucher_ID, newVoucher.Voucher_ID, userID, 1, BulkVoucherAmount, 1);
                //buy bulk transaction on blockchain
                MResellerController resellerCtrl = new MResellerController(userID);
                resellerCtrl = await resellerCtrl.init();

                await resellerCtrl.buyBulk(Decimal.ToInt32(BulkVoucherAmount));

                return(Ok());
            }
            else
            {
                return(BadRequest("User not a valid reseller"));
            }
        }
Exemplo n.º 3
0
        public bool PurchaseProducts()
        {
            List <voucher> voucherlist = (from c in db.vouchers where c.voucherValue >= 10 select c).ToList();

            product[]  productList  = (from c in db.products select c).ToArray();
            consumer[] consumerList = (from c in db.consumers select c).ToArray();

            foreach (voucher temp in voucherlist)
            {
                for (int i = 0; i < 5; i++)
                {
                    voucher newVoucher = new voucher();
                    newVoucher.User_ID        = consumerList[r.Next(41)].User_ID;
                    newVoucher.voucherValue   = (Decimal)((int)temp.voucherValue * 0.2);
                    newVoucher.VoucherType_ID = 2;
                    DateTime now = temp.voucherCreationDate.Value.AddHours(r.Next(150));
                    now.ToString("yyyy-MM-dd H:mm:ss");

                    newVoucher.voucherCreationDate = now;
                    db.vouchers.Add(newVoucher);
                    db.SaveChanges();
                }

                temp.voucherValue = 0;
                db.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 4
0
        public bool ModifyHistory(int voucherID, int consumerVoucherID)
        {
            List <voucher> voucherlist = (from c in db.vouchers where c.VoucherType_ID == 1 && c.Voucher_ID > voucherID select c).ToList();

            //consumer [] consumerList = (from c in db.consumers select c).ToArray();
            voucher[] consumerVouchers = (from c in db.vouchers where c.VoucherType_ID == 2 && c.Voucher_ID > consumerVoucherID select c).ToArray();
            int       counter          = 1;


            foreach (voucher temp in voucherlist)
            {
                int     value  = (int)temp.voucherValue;
                decimal amount = (Decimal)(value * 0.2);
                voucher cons   = consumerVouchers[counter];

                for (int i = 0; i < 5; i++)
                {
                    //counter++;
                    consumerVouchers[counter].voucherValue = amount;
                    addVoucherTransaction(consumerVouchers[counter].Voucher_ID, temp.Voucher_ID, cons.User_ID, temp.User_ID, amount, 2, (DateTime)consumerVouchers[counter].voucherCreationDate);

                    db.SaveChanges();
                }

                temp.voucherValue = 0;
                db.SaveChanges();
            }
            return(true);
        }
Exemplo n.º 5
0
        public override global::System.Data.DataSet Clone()
        {
            voucher cln = ((voucher)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            voucher voucher = await db.vouchers.FindAsync(id);

            db.vouchers.Remove(voucher);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 7
0
        public async Task <DTOvoucher> Postvoucher(DTOvoucher newDTO)
        {
            voucher newProd = EntityMapper.updateEntity(null, newDTO);

            db.vouchers.Add(newProd);
            await db.SaveChangesAsync();

            return(newDTO);
        }
Exemplo n.º 8
0
        public Voucher(voucher voucher)
        {
            this.id    = voucher.id;
            this.name  = voucher.name;
            this.price = voucher.price;

            this.startDate = voucher.startDate;
            this.endDate   = voucher.endDate;
            this.status    = voucher.status;
        }
Exemplo n.º 9
0
        public async Task <IHttpActionResult> Putvoucher(int ID, DTOvoucher editedDTO)
        {
            voucher toUpdate = db.vouchers.Find(ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 10
0
        public JsonResult findVoucherById()
        {
            int     vouId     = int.Parse(Request.QueryString["voucherId"]);
            voucher voucher   = db.vouchers.Find(vouId);
            String  startDate = Convert.ToDateTime(voucher.startDate).ToString("yyyy-MM-dd");
            String  endDate   = Convert.ToDateTime(voucher.endDate).ToString("yyyy-MM-dd");

            Voucher v = new Voucher(voucher.id, voucher.name, voucher.productId, voucher.price, voucher.status, voucher.activeFlag, startDate, endDate, new product(voucher.product.id, voucher.product.name));

            return(Json(v, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Edit([Bind(Include = "voucher_id,image,valid_start_date,valid_end_date,description,active,last_updated")] voucher voucher)
        {
            if (ModelState.IsValid)
            {
                db.Entry(voucher).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(voucher));
        }
Exemplo n.º 12
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            voucher ds = new voucher();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Exemplo n.º 13
0
        public JsonResult addVoucher(VoucherForm voucherForm)
        {
            System.Diagnostics.Debug.WriteLine("name " + voucherForm.Name);
            System.Diagnostics.Debug.WriteLine("product id " + voucherForm.ProductId);
            System.Diagnostics.Debug.WriteLine("voucher id " + voucherForm.VoucherId);
            System.Diagnostics.Debug.WriteLine("price " + voucherForm.Price);
            System.Diagnostics.Debug.WriteLine("start " + voucherForm.StartDate);
            System.Diagnostics.Debug.WriteLine("end " + voucherForm.EndDate);
            string message = "";


            //update
            if (voucherForm.VoucherId != 0)
            {
                voucher  v         = db.vouchers.Find(voucherForm.VoucherId);
                DateTime startDate = DateTime.Parse(voucherForm.StartDate);

                DateTime endDate = DateTime.Parse(voucherForm.EndDate);
                v.startDate = startDate;
                v.endDate   = endDate;
                v.name      = voucherForm.Name;
                v.product   = db.products.Find(voucherForm.ProductId);
                v.price     = voucherForm.Price;

                db.Entry(v).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
            else
            {
                voucher v = new voucher();
                v.name    = voucherForm.Name;
                v.price   = voucherForm.Price;
                v.product = db.products.Find(voucherForm.ProductId);
                DateTime startDate = DateTime.Parse(voucherForm.StartDate);

                DateTime endDate = DateTime.Parse(voucherForm.EndDate);
                v.startDate  = startDate;
                v.endDate    = endDate;
                v.createDate = DateTime.Now;
                v.updateDate = DateTime.Now;
                v.activeFlag = 1;
                v.status     = 1;

                this.db.vouchers.Add(v);
                this.db.SaveChanges();

                message = "SUCCESS";
            }



            return(Json(new { Message = message }, JsonRequestBehavior.AllowGet));
        }
        public async Task <ActionResult> Create([Bind(Include = "voucher_id,image,valid_start_date,valid_end_date,description,active,last_updated")] voucher voucher)
        {
            if (ModelState.IsValid)
            {
                db.vouchers.Add(voucher);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(voucher));
        }
Exemplo n.º 15
0
        public ActionResult MakeVoucher(string code, int percentage)
        {
            voucher v = new voucher();

            v.code       = code;
            v.percentage = percentage;

            CinemaWebServiceClient c = new CinemaWebServiceClient();

            c.createVoucher(v);

            return(RedirectToAction("AllVouchers"));
        }
Exemplo n.º 16
0
        private void refundConsumer(int userID, decimal voucherAmout)
        {
            voucher newVoucher = new voucher();

            newVoucher.User_ID             = userID;
            newVoucher.voucherValue        = voucherAmout;
            newVoucher.VoucherType_ID      = 2;
            newVoucher.voucherCreationDate = DateTime.Now;
            db.vouchers.Add(newVoucher);
            db.SaveChanges();

            addVoucherTransaction(newVoucher.Voucher_ID, newVoucher.Voucher_ID, userID, 1, voucherAmout, 41);
        }
Exemplo n.º 17
0
        public List <voucher> GetVoucherList(int uid)
        {
            List <voucher> lv  = new List <voucher>();
            string         sql = "select * from t_voucher where uid = " + uid + " and enable = 0 order by addOn asc";

            try
            {
                using (DataTable dt = helper.GetDataTable(sql))
                {
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        foreach (DataRow r in dt.Rows)
                        {
                            voucher v = new voucher
                            {
                                id           = Convert.ToInt32(r["id"]),
                                voucherFee   = Convert.ToInt16(r["voucherFee"]),
                                voucherNo    = r["voucherNo"].ToString(),
                                voucherTitle = r["voucherTitle"].ToString(),
                                addOn        = Convert.ToDateTime(r["addOn"]),
                                endOn        = Convert.ToDateTime(r["endOn"]),
                                enable       = Convert.ToInt16(r["enable"]),
                                voucherType  = Convert.ToInt16(r["voucherType"]),
                                orderNo      = r["orderNo"].ToString(),
                                uid          = Convert.ToInt32(r["uid"]),
                                srcUid       = Convert.ToInt32(r["srcUid"]),
                                cardId       = r["cardId"].ToString()
                            };
                            if (v.enable == 1)
                            {
                                v.useOn  = Convert.ToDateTime(r["useOn"]);
                                v.useFee = Convert.ToDouble(r["useFee"]);
                            }
                            if (v.enable == 0)
                            {
                                if (DateTime.Now.Date < v.endOn.Date)
                                {
                                    v.enable = 3;
                                }
                            }
                            lv.Add(v);
                        }
                    }
                }
            }
            catch
            {
            }
            return(lv);
        }
        // GET: Vouchers/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            voucher voucher = await db.vouchers.FindAsync(id);

            if (voucher == null)
            {
                return(HttpNotFound());
            }
            return(View(voucher));
        }
Exemplo n.º 19
0
        // GET: Admin/RestVoucher
        public JsonResult loadProduct()
        {
            int            voucherId = int.Parse(Request.QueryString["voucherId"]);
            voucher        voucher   = db.vouchers.Find(voucherId);
            List <product> products  = new List <product>();

            foreach (product p in voucher.products)
            {
                products.Add(new product(p.id, p.name));
            }



            return(Json(products, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 20
0
        //BUSCA EL VOUCHER EN LA DB, SI NO ES VALIDO DEVUELVE UN ID="INVALIDO"
        //si el id es igual al de db, esta activo,fue comprado, no fue utilizado antes y esta en el sorteo actual, EN RESUMEN, VERIFICA SI ES VALIDO
        //PERO NO SI TIENE PREMIO
        public voucher buscarXID(string id)
        {
            AccesoDatosManager accesoDatos = new AccesoDatosManager();
            voucher            voucher     = new voucher("INVALIDO", DateTime.Now, false, 0, 0);

            try
            {
                accesoDatos.setearSP("SP_BUSCAR_VOUCHER_X_ID");                                                   //SETEO EL SP

                SqlParameter[] VectorParam = new SqlParameter[1];                                                 //no funciona con lista, aqui se debe agregar la cantidad de parametros totales

                accesoDatos.agregarParametroSP(VectorParam, 0, "@ID_VOUCHER", System.Data.SqlDbType.VarChar, id); // AGREGO UN PARAMETRO AL VECTOR EN ESA POSICION


                accesoDatos.Comando.Parameters.AddRange(VectorParam); //AGREGO LA MATRIZ DE PARAMETROS A LOS PARAMETROS DEL COMANDO

                accesoDatos.abrirConexion();                          // abro conexion
                accesoDatos.ejecutarConsulta();                       //EJECUTO EL SP

                while (accesoDatos.Lector.Read())
                {
                    voucher voucherNew = new voucher(accesoDatos.Lector.GetString(0), accesoDatos.Lector.GetDateTime(1), accesoDatos.Lector.GetBoolean(2), accesoDatos.Lector.GetInt32(3), 0);
                    voucher = voucherNew;
                }

                if (voucher.Id == id && voucher.Activo == true)
                {
                    return(voucher);
                }
                else
                {
                    voucher.Id = "INVALIDO";
                    return(voucher);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                accesoDatos.cerrarConexion();//CIERRO CONEXION
            }
        }
Exemplo n.º 21
0
        //POST...add a voucher: use cases involved:
        //-reseller buys voucher online= reseller gets a brand new bulk voucher added
        //-= consumer gets a brand new normal voucher added

        //PUT...update a voucher: use cases involved:
        //-reseller sends voucher= update reseller's voucher amount
        public IHttpActionResult SendVoucher(int senderID, int receiverID, decimal amountToSend, int transactionType_ID, int voucherTypeID)
        {
            if (getVoucherAccountBalance(senderID) < amountToSend)
            {
                return(BadRequest("invalid funds")); // or custom responce for invalid funds
            }

            Decimal        toDeduct       = amountToSend;
            List <voucher> senderVouchers = (from c in db.vouchers where c.User_ID == senderID && c.voucherValue > 0 orderby c.voucherValue ascending select c).ToList();

            voucher newVoucher = new voucher();

            newVoucher.User_ID        = receiverID;
            newVoucher.voucherValue   = amountToSend;
            newVoucher.VoucherType_ID = voucherTypeID;
            DateTime now = DateTime.Now;

            now.ToString("yyyy-MM-dd H:mm:ss");
            newVoucher.voucherCreationDate = now;
            db.vouchers.Add(newVoucher);
            db.SaveChanges();


            for (int i = 0; i < senderVouchers.Count && toDeduct > 0; i++)
            {
                voucher temp = senderVouchers.ElementAt(i);

                if (toDeduct >= temp.voucherValue)
                {
                    toDeduct -= temp.voucherValue;
                    addVoucherTransaction(newVoucher.Voucher_ID, temp.Voucher_ID, receiverID, senderID, temp.voucherValue, transactionType_ID);
                    temp.voucherValue = 0;
                }
                else
                {
                    temp.voucherValue -= toDeduct;
                    addVoucherTransaction(newVoucher.Voucher_ID, temp.Voucher_ID, receiverID, senderID, toDeduct, transactionType_ID);
                    toDeduct = 0;
                }
            }

            return(Ok());
        }
Exemplo n.º 22
0
        public static voucher updateEntity(voucher entityObjct, DTOvoucher dto)
        {
            if (entityObjct == null)
            {
                entityObjct = new voucher();
            }

            entityObjct.Voucher_ID          = dto.Voucher_ID;
            entityObjct.VoucherType_ID      = dto.VoucherType_ID;
            entityObjct.User_ID             = dto.User_ID;
            entityObjct.voucherValue        = dto.voucherValue;
            entityObjct.voucherCreationDate = dto.voucherCreationDate;
            entityObjct.OTP         = dto.OTP;
            entityObjct.OTPtimeStap = dto.OTPtimeStap;
            entityObjct.QRdata      = dto.QRdata;
            entityObjct.QRtimeStap  = dto.QRtimeStap;

            return(entityObjct);
        }
Exemplo n.º 23
0
        public void SendVoucherForWs(int uid, int srcUid)
        {
            voucher v = null;

            //1张20
            for (int i = 0; i < 2; i++)
            {
                v = new voucher
                {
                    uid          = uid,
                    voucherFee   = 10,
                    voucherNo    = "R" + DateTime.Now.ToString("yyMMddHHmmss") + uid.ToString().PadLeft(4, '0') + "02" + i.ToString(),
                    enable       = 0,
                    addOn        = DateTime.Now,
                    srcUid       = srcUid,
                    voucherTitle = "现金红包",
                    //endOn = DateTime.Now.AddDays(30),
                    endOn       = Convert.ToDateTime("2017-12-31"),//DateTime.Now.AddMonths(1),
                    voucherType = 0
                };
                new Main().AddToDb(v, "t_voucher");
            }

            //2张50
            for (int i = 0; i < 10; i++)
            {
                v = new voucher
                {
                    uid          = uid,
                    voucherFee   = 10,
                    voucherNo    = "R" + DateTime.Now.ToString("yyMMddHHmmss") + uid.ToString().PadLeft(4, '0') + "03" + i.ToString(),
                    enable       = 0,
                    addOn        = DateTime.Now,
                    srcUid       = srcUid,
                    voucherTitle = "现金红包",
                    //endOn = DateTime.Now.AddDays(30),
                    endOn       = Convert.ToDateTime("2017-12-31"),//DateTime.Now.AddMonths(1),
                    voucherType = 0
                };
                new Main().AddToDb(v, "t_voucher");
            }
        }
Exemplo n.º 24
0
        //VERIFICA SI EL VOUCHER EXISTE EN LA DB CON CIERTAS CONDICIONES
        //si el id es igual al de db, esta activo,fue comprado, no fue utilizado antes y esta en el sorteo actual Y TIENE PREMIOS
        public bool isWin(string id)
        {
            AccesoDatosManager accesoDatos = new AccesoDatosManager();
            voucher            voucher     = this.buscarXID(id);
            bool result = false;

            try
            {
                //si lo encuentra revisa si tiene premios
                if (voucher.Id == id)
                {
                    accesoDatos.setearSP("SP_IS_WIN");                                                                        //SETEO EL SP

                    SqlParameter[] VectorParam = new SqlParameter[1];                                                         //no funciona con lista, aqui se debe agregar la cantidad de parametros totales

                    accesoDatos.agregarParametroSP(VectorParam, 0, "@ID_VOUCHER", System.Data.SqlDbType.VarChar, voucher.Id); // AGREGO UN PARAMETRO AL VECTOR EN ESA POSICION


                    accesoDatos.Comando.Parameters.AddRange(VectorParam); //AGREGO LA MATRIZ DE PARAMETROS A LOS PARAMETROS DEL COMANDO

                    accesoDatos.abrirConexion();                          // abro conexion
                    accesoDatos.ejecutarConsulta();                       //EJECUTO EL SP

                    while (accesoDatos.Lector.Read())
                    {
                        result = accesoDatos.Lector.GetBoolean(0);
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                accesoDatos.cerrarConexion();//CIERRO CONEXION
            }
        }
Exemplo n.º 25
0
        public JsonResult deleteVoucher(VoucherForm voucherForm)
        {
            string message = "";

            System.Diagnostics.Debug.WriteLine("voucher id " + voucherForm.VoucherId);
            if (voucherForm.VoucherId != 0)
            {
                try
                {
                    voucher v = db.vouchers.Find(voucherForm.VoucherId);
                    v.activeFlag      = 0;
                    db.Entry(v).State = System.Data.EntityState.Modified;
                    db.SaveChanges();
                    message = "SUCCESS";
                }
                catch (Exception e)
                {
                    message = "FAIL";
                }
            }

            return(Json(new { Message = message }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 26
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                voucher ds = new voucher();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "voucherDataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }
Exemplo n.º 27
0
        /// <summary>
        /// 获取代金券列表
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="orderNo"></param>
        /// <param name="enable"></param>
        /// <returns></returns>
        public List <voucher> GetVoucherList(int uid, string orderNo, int enable, string voucherNo)
        {
            List <voucher> lv  = new List <voucher>();
            string         sql = "select * from t_voucher where uId = " + uid + " order by endOn asc,enable asc";

            if (orderNo.Length > 0)
            {
                sql = "select * from t_voucher where orderNo = '" + orderNo + "' order by endOn asc,enable asc";
            }
            if (enable > -1)
            {
                sql = "select * from t_voucher where uId = " + uid + " and enable = " + enable + " order by endOn asc,enable asc";
                if (orderNo.Length > 0)
                {
                    sql = "select * from t_voucher where orderNo = '" + orderNo + "' and enable = " + enable + " order by endOn asc,enable asc";
                }
            }
            if (voucherNo.Length > 0)
            {
                sql = "select * from t_voucher where voucherNo = '" + voucherNo + "' order by endOn asc,enable asc";
            }

            try
            {
                using (DataTable dt = helper.GetDataTable(sql))
                {
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        foreach (DataRow r in dt.Rows)
                        {
                            voucher v = new voucher
                            {
                                id           = Convert.ToInt32(r["id"]),
                                voucherFee   = Convert.ToInt16(r["voucherFee"]),
                                voucherNo    = r["voucherNo"].ToString(),
                                voucherTitle = r["voucherTitle"].ToString(),
                                addOn        = Convert.ToDateTime(r["addOn"]),
                                endOn        = Convert.ToDateTime(r["endOn"]),
                                enable       = Convert.ToInt16(r["enable"]),
                                voucherType  = Convert.ToInt16(r["voucherType"]),
                                orderNo      = r["orderNo"].ToString(),
                                uid          = Convert.ToInt32(r["uid"]),
                                srcUid       = Convert.ToInt32(r["srcUid"]),
                                cardId       = r["cardId"].ToString()
                            };
                            if (v.enable == 1)
                            {
                                v.useOn  = Convert.ToDateTime(r["useOn"]);
                                v.useFee = Convert.ToDouble(r["useFee"]);
                            }
                            if (v.enable == 0)
                            {
                                if (DateTime.Now.Date > v.endOn.Date)
                                {
                                    v.enable = 3;
                                }
                            }
                            if (enable == 0)
                            {
                                if (v.enable == 0)
                                {
                                    lv.Add(v);
                                }
                            }
                            else
                            {
                                lv.Add(v);
                            }
                        }
                    }
                }
            }
            catch
            {
            }
            return(lv);
        }
Exemplo n.º 28
0
 public static Voucher ToSvc(this voucher item)
 {
     return(new Voucher(item));
 }
Exemplo n.º 29
0
        private void SetInfo(HttpContext context)
        {
            string vouchers = context.Request["vouchers"];

            if (string.IsNullOrEmpty(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 5, "Hãy nhập gói cước"));
                return;
            }

            var oUser = (CustomerGateInfo)context.Session[Config.GetSessionUser];

            if (oUser == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 6, "Hết phiên làm việc, hãy thực hiện lại"));
                return;
            }

            if (!Utility.isOnlyNumber(vouchers))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 7, "Gói cước không phù hợp"));
                return;
            }

            List <voucher> list     = oUser.vouchers;
            voucher        oVoucher = null;

            foreach (voucher item in list)
            {
                if (vouchers == item.vouchervalue)
                {
                    oVoucher = item;
                    break;
                }
            }

            if (oVoucher == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 8, "Gói cước không phù hợp"));
                return;
            }

            SmartlinkRedirectUrlInfo oRedirectUrlInfo = new SmartlinkRedirectUrlInfo()
            {
                CreateDate = DateTime.Now
            };

            try
            {
                string sUrl = SmartLinkHelper.getRedirectUrl(vouchers, ref oRedirectUrlInfo);

                //save cached
                CacheInfo oCacheInfo = new CacheInfo()
                {
                    Voucher   = oVoucher,
                    sTrans_Id = oRedirectUrlInfo.vpc_MerchTxnRef,
                    User      = oUser
                };

                CacheProvider.AddWithTimeOut(string.Format(KeyCache.KeyUserSmartlink, oRedirectUrlInfo.vpc_MerchTxnRef), oCacheInfo, 720);
                //
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 0, sUrl));
            }
            catch (Exception ex)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", ex.GetHashCode().ToString(), ex.Message));
            }
            finally
            {
                SmartlinkRedirectUrlData.instance.Add(oRedirectUrlInfo);
            }
        }
Exemplo n.º 30
0
 public Voucher(voucher voucher)
 {
 }