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(); } } }
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); }
public PartialViewResult GiftMaker(GiftViewModel data) { var result = new GiftModel(data.Message); result.GenerateGif(); return(PartialView(result)); }
private void GiftView_Load(object sender, EventArgs e) { GiftModel gm = new GiftModel(); g_idTextEdit.Text = gm.getNextID(); g_statusTextEdit.SelectedItem = "Active"; }
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); } }
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)); }
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)); }
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); } }
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."); }
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")); }
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; }
// 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)); }
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); } }
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(); } } }
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(); } } }
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); } } }
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); } }
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)); }); }
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); }
public ActionResult giftCreation(GiftModel gifttoadd) { Services.Services.addAGift(gifttoadd); return(RedirectToAction("Index")); }
public ActionResult giftEdit(GiftModel gifttoedit) { Services.Services.editGift(gifttoedit); return(RedirectToAction("Index")); }
//POST public ActionResult Open(int id) { GiftModel gift = Services.Services.getAGift(id); return(View(gift)); }
private void g_idTextEdit_Click(object sender, EventArgs e) { GiftModel gm = new GiftModel(); g_idTextEdit.Text = gm.getNextID(); }