예제 #1
0
        public static void addAGift(GiftModel gift)
        {
            using (var connection = new SqlConnection(connectionStrings))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = @"INSERT INTO Gifts VALUES (@Contents, @GiftHint, @ColorWrappingPaper, @Height, @Width, @Depth,  @Weight, @isOpened)";
                    cmd.Parameters.AddWithValue("@Contents", gift.Contents);
                    cmd.Parameters.AddWithValue("@GiftHint", gift.GiftHint);
                    cmd.Parameters.AddWithValue("@ColorWrappingPaper", gift.ColorWrappingPaper);
                    cmd.Parameters.AddWithValue("@Height", gift.Height);
                    cmd.Parameters.AddWithValue("@Width", gift.Width);
                    cmd.Parameters.AddWithValue("@Depth", gift.Depth);
                    cmd.Parameters.AddWithValue("@Weight", gift.Weight);
                    cmd.Parameters.AddWithValue("@isOpened", gift.isOpened);


                    connection.Open();
                    var reader = cmd.ExecuteReader();
                    connection.Close();
                }
            }
        }
예제 #2
0
        public static List <GiftModel> GetGiftsByAccountID(int accID)
        {
            var list = new List <GiftModel>();

            var sqlText    = "SELECT * FROM gifts WHERE Target=@target";
            var sqlCommand = new MySqlCommand(sqlText, Program.DBHelper.Use());

            sqlCommand.Parameters.Add(new MySqlParameter("@target", accID));

            var sqlReader = sqlCommand.ExecuteReader();

            while (sqlReader.Read())
            {
                var gift = new GiftModel()
                {
                    ID      = sqlReader.GetInt16("Id"),
                    Target  = sqlReader.GetInt16("Target"),
                    ItemID  = sqlReader.GetInt16("ItemID"),
                    Title   = sqlReader.GetString("Title"),
                    Message = sqlReader.GetString("Message"),
                    Image   = sqlReader.GetString("Image"),
                };

                list.Add(gift);
            }

            sqlReader.Close();

            return(list);
        }
예제 #3
0
        public PartialViewResult GiftMaker(GiftViewModel data)
        {
            var result = new GiftModel(data.Message);

            result.GenerateGif();
            return(PartialView(result));
        }
예제 #4
0
        private void GiftView_Load(object sender, EventArgs e)
        {
            GiftModel gm = new GiftModel();

            g_idTextEdit.Text             = gm.getNextID();
            g_statusTextEdit.SelectedItem = "Active";
        }
예제 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            GiftModel giftModel = db.GiftModels.Find(id);

            db.GiftModels.Remove(giftModel);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void btnSaveEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (txt_gName.Text != "")
            {
                GiftModel gm           = new GiftModel();
                String    image        = "";
                String    oldImageName = gm.getGift(txt_gID.Text).g_image;
                if (txt_gImage.Text != "")
                {
                    if (openDialog.FileName.EndsWith(".jpg"))
                    {
                        image = txt_gID.Text + ".jpg";
                    }
                    else
                    {
                        image = txt_gID.Text + ".png";
                    }

                    //get path app project
                    String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
                    //old image file path
                    String oldFilePath = projectPath + "\\img\\" + oldImageName;
                    //delete old image file if exist
                    FileInfo f = new FileInfo(oldFilePath);
                    if (f.Exists)
                    {
                        File.Delete(oldFilePath);
                    }

                    //get solution path
                    String solutionPath   = Directory.GetParent(projectPath).FullName;;
                    String oldWebFilePath = solutionPath + "\\PetStoreWebClient\\Assets\\images\\" + oldImageName;
                    //delete old image file if exist
                    FileInfo f2 = new FileInfo(oldWebFilePath);
                    if (f2.Exists)
                    {
                        File.Delete(oldWebFilePath);
                    }

                    //Get new image file path and copy it to image folder
                    String newFilepath    = Path.GetFullPath(projectPath + "\\img\\" + image);
                    String newFileWebpath = Path.GetFullPath(solutionPath + "\\PetStoreWebClient\\Assets\\images\\" + image);
                    File.Copy(txt_gImage.Text, newFileWebpath);
                    File.Copy(txt_gImage.Text, newFilepath);
                }
                else
                {
                    image = oldImageName;
                }
                gm.UpdateGift(txt_gID.Text, txt_gName.Text, txt_gStatus.Text, image);
                XtraMessageBox.Show("Edit successful !!!", "Congratulation", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                XtraMessageBox.Show("Please fill in full information !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #7
0
 public ActionResult Edit([Bind(Include = "Id,name,description,numberAvailable")] GiftModel giftModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(giftModel).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(giftModel));
 }
예제 #8
0
        public ActionResult Create([Bind(Include = "Id,name,description,numberAvailable")] GiftModel giftModel)
        {
            if (ModelState.IsValid)
            {
                db.GiftModels.Add(giftModel);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(giftModel));
        }
예제 #9
0
 private void bbiRestore_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (gIDSelected != "")
     {
         GiftModel gm = new GiftModel();
         gm.RestoreGift(gIDSelected);
         XtraMessageBox.Show("Restore successful !!!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         XtraMessageBox.Show("Please choose a gift item to restore !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
예제 #10
0
        private static void CreateNewGiftEntry(ISqlCrud sqlCrud)
        {
            GiftModel gift = new GiftModel
            {
                GiftName  = "Barbie Doll",
                GiftCost  = 15,
                ContactId = 4
            };

            sqlCrud.CreateGiftEntry(gift);

            Console.WriteLine($"Gift data entry conmplete.");
        }
예제 #11
0
        public async Task <int> CreateGiftEntry(GiftModel gift)
        {
            DynamicParameters p = new DynamicParameters();

            p.Add("GiftName", gift.GiftName);
            p.Add("GiftCost", gift.GiftCost);
            p.Add("ContactId", gift.ContactId);
            p.Add("Id", DbType.Int32, direction: ParameterDirection.Output);

            await _dataAccess.SaveDataAsync("dbo.spGift_insert", p, _connectionString.SqlConnectionName);

            return(p.Get <int>("Id"));
        }
예제 #12
0
 public GiftModel Create(Gift gift)
 {
     if (gift == null)
     {
         return null;
     }
     var result = new GiftModel
     {
         Id = gift.Id,
         GiftName = gift.GiftName,
         Images = gift.Images
     };
     return result;
 }
예제 #13
0
        // GET: Gifts/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            GiftModel giftModel = db.GiftModels.Find(id);

            if (giftModel == null)
            {
                return(HttpNotFound());
            }
            return(View(giftModel));
        }
예제 #14
0
        public static List <GiftModel> getAllGifts()
        {
            var rv = new List <GiftModel>();

            using (var connection = new SqlConnection(connectionStrings))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = @"SELECT Id, Contents, GiftHint, ColorWrappingPaper, Height, Width, Depth, Weight, isOpened FROM Gifts";

                    connection.Open();
                    var reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var id                 = reader["Id"];
                        var Contents           = reader[1];
                        var GiftHint           = reader[2];
                        var ColorWrappingPaper = reader[3];
                        var Height             = reader[4];
                        var Width              = reader[5];
                        var Depth              = reader[6];
                        var Weight             = reader[7];
                        var isOpened           = reader[8];

                        var dblheight = parseSqlDouble(Height);
                        var dblweight = parseSqlDouble(Weight);
                        var dblwidth  = parseSqlDouble(Width);
                        var dbldepth  = parseSqlDouble(Depth);
                        var gift      = new GiftModel
                        {
                            Id                 = (int)id,
                            Contents           = Contents as string,
                            GiftHint           = GiftHint as string,
                            ColorWrappingPaper = ColorWrappingPaper as string,
                            Height             = dblheight,
                            Width              = dblwidth,
                            Depth              = dbldepth,
                            Weight             = dblweight,
                            isOpened           = isOpened as bool?
                        };
                        rv.Add(gift);
                    }
                    connection.Close();
                }
                return(rv);
            }
        }
예제 #15
0
        public static void editGift(GiftModel gift)
        {
            using (var connection = new SqlConnection(connectionStrings))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = $@"UPDATE Gifts SET Contents='{gift.Contents}', GiftHint='{gift.GiftHint}', ColorWrappingPaper='{gift.ColorWrappingPaper}', Height='{gift.Height}', Width='{gift.Width}', Depth='{gift.Depth}', Weight='{gift.Weight}' WHERE Id={gift.Id};";

                    connection.Open();
                    var reader = cmd.ExecuteReader();
                    connection.Close();
                }
            }
        }
예제 #16
0
        public static void openGift(GiftModel gift)
        {
            using (var connection = new SqlConnection(connectionStrings))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection  = connection;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = $@"UPDATE Gifts SET isOpened=1 WHERE Id={gift.Id};";

                    connection.Open();
                    var reader = cmd.ExecuteReader();
                    connection.Close();
                }
            }
        }
예제 #17
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         int productId;
         if (!int.TryParse(Request.QueryString["productId"], out productId))
         {
             productId = 0;
         }
         GiftBll gbll = new GiftBll();
         model = gbll.GetModel(productId);
         if (model == null)
         {
             throw new ShopException("你查找的积分商品不存在", true);
         }
     }
 }
예제 #18
0
 private void g_imageTextEdit_Click(object sender, EventArgs e)
 {
     openDialog.Filter = "Image files (*.jpg)|*.jpg|Image files (*.png)|*.png|All files (*.*)|*.*";
     openDialog.ShowDialog();
     if (openDialog.FileName != "" && (openDialog.FileName.EndsWith(".jpg") || openDialog.FileName.EndsWith(".png")))
     {
         GiftModel gm = new GiftModel();
         if (openDialog.FileName.EndsWith(".jpg"))
         {
             g_imageTextEdit.Text = gm.getNextID() + ".jpg";
         }
         else
         {
             g_imageTextEdit.Text = gm.getNextID() + ".png";
         }
     }
     else
     {
         XtraMessageBox.Show("Please choose a image with (*.jpg)/(*.png) file !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
예제 #19
0
        protected override void Configure()
        {
            //// To GiftModel
            Mapper.CreateMap <string, GiftModel>()
            .ConvertUsing(i =>
            {
                var giftData          = i.Split(':');
                var giftModel         = new GiftModel();
                giftModel.Name        = giftData[0];
                giftModel.Description = giftData[1];

                return(giftModel);
            });

            Mapper.CreateMap <string, IEnumerable <GiftModel> >()
            .ConvertUsing(i =>
            {
                var giftSourceList = i.Split(';');

                return(Mapper.Map <List <GiftModel> >(giftSourceList));
            });
        }
예제 #20
0
        private void bbiDetail_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (gIDSelected != "")
            {
                DetailGift dg = new DetailGift();
                GiftModel  gm = new GiftModel();

                Gift g = gm.getGift(gIDSelected);

                dg.txt_pID.Text     = g.g_id;
                dg.txt_gName.Text   = g.g_name;
                dg.txt_gStatus.Text = g.g_status;

                if (g.g_status == "Active")
                {
                    dg.txt_gStatus.ForeColor = Color.Green;
                    dg.txt_gStatus.Text      = g.g_status;
                }
                else
                {
                    dg.txt_gStatus.ForeColor = Color.Red;
                    dg.txt_gStatus.Text      = g.g_status;
                }

                dg.lblTitle.Text = g.g_name;

                String projectPath = Path.GetFullPath(Path.Combine(Application.StartupPath, "..\\.."));
                String pathImage   = projectPath + "\\img\\" + g.g_image;
                Image  img         = Image.FromFile(pathImage);
                dg.ptbImage.Image = gm.ResizeImage(img, 440, 440);

                dg.ShowDialog();
            }
            else
            {
                MessageBox.Show("Please choose a gift to view detail !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
 public void 當執行轉換字串為GiftModel()
 {
     this.gift = Mapper.Map <GiftModel>(this.giftString);
 }
예제 #22
0
 public ActionResult giftCreation(GiftModel gifttoadd)
 {
     Services.Services.addAGift(gifttoadd);
     return(RedirectToAction("Index"));
 }
예제 #23
0
 public ActionResult giftEdit(GiftModel gifttoedit)
 {
     Services.Services.editGift(gifttoedit);
     return(RedirectToAction("Index"));
 }
예제 #24
0
        //POST
        public ActionResult Open(int id)
        {
            GiftModel gift = Services.Services.getAGift(id);

            return(View(gift));
        }
예제 #25
0
        private void g_idTextEdit_Click(object sender, EventArgs e)
        {
            GiftModel gm = new GiftModel();

            g_idTextEdit.Text = gm.getNextID();
        }