/// <summary> /// Handles the ItemCommand event of the ImageListView control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="ListViewCommandEventArgs" /> instance containing the event data.</param> protected void ImageListView_ItemCommand(object sender, ListViewCommandEventArgs e) { /* We have not bound the control to any DataSource derived controls, * nor do we use any key to identify the image. Hence, it makes more sense not to * use 'delete' but to use a custom command 'Remove' which can be fired as a * generic ItemCommand, and the ListViewCommandEventArgs e will have * the CommandArgument passed by the 'Remove' button In this case, it is the bound * ImageUrl that we are passing, and making use it of to delete the image.*/ var di = this.Session["DisplayInfo"] as DisplayInfo; IStoreDataSource ds = new StoreDataProvider(di.ConnStr); switch (e.CommandName) { case "SelectItem": var itemId = Convert.ToInt32(e.CommandArgument); var mediaObject = ds.LoadMediaFile(itemId); this.Session["EditingItem"] = mediaObject; this.ddlGroup.SelectedValue = mediaObject.GroupId.ToString(); break; case "Remove": int item = Convert.ToInt32(e.CommandArgument); ds.DeleteImage(item); break; case "Update": throw new NotImplementedException(); break; default: break; } }
/// <summary> /// Loads the versions. /// </summary> private void LoadCatalog() { var di = this.Session["DisplayInfo"] as DisplayInfo; if (di != null) { IStoreDataSource ds = new StoreDataProvider(di.ConnStr); this.catalogControl.Controls.Clear(); var catalog = ds.LoadCatalog(); foreach (var catalogItem in catalog) { var ctrl = LoadControl(@"~\Controls\LinkButtonControl.ascx") as LinkButtonControl; if (ctrl != null) { ctrl.ID = string.Format("CatalogItem_{0}", catalogItem.Id); string pageUrl = Request.Url.AbsoluteUri; if (!string.IsNullOrEmpty(Request.Url.Query)) { pageUrl = pageUrl.Replace(Request.Url.Query, string.Empty); } ctrl.Url = string.Format("{0}?catalog={1}", pageUrl, catalogItem.Id); ctrl.Text = catalogItem.Caption; this.catalogControl.Controls.Add(ctrl); } } } Page.DataBind(); }
public void OldDataProvider_LoadAllMedia_OperationResult() { IStoreDataSource ds = new StoreDataProvider(this.databaseConnString); List <MediaDraft> list = ds.LoadAllMedia().ToList(); Assert.IsNotNull(list); }
public void ClosestStoreTest() { String closestStoreNum = "34"; StoreDataProvider provider = new StoreDataProvider(); DistanceCalculator calculator = new DistanceCalculator(); calculator.StoreProv = provider; string actualStore = calculator.GetClosestStoreDistance(CustomerLocation).StoreNo.ToString(); Assert.AreEqual(closestStoreNum, actualStore); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void BtnSave_Click(object sender, EventArgs e) { var item = this.Session["EditingItem"] as MediaDraft; item.GroupId = Convert.ToInt32(this.ddlGroup.SelectedValue); var di = this.Session["DisplayInfo"] as DisplayInfo; IStoreDataSource ds = new StoreDataProvider(di.ConnStr); ds.UpdateMedia(item); this.Session["EditingItem"] = null; }
/// <summary> /// 取消设置数据提供者 /// </summary> /// <param name="context">数据安全上下文</param> public void RemoveRegisterProvider(int context) { if (StoreDataProvider != null) { if (context != currentHolderContext) { GameErrorManager.SetLastErrorAndLog(GameError.ContextMismatch, "StoreData", "上下文 {0} 没有操作此数据的权限", context); return; } StoreDataProvider = null; } }
/// <summary> /// Gets the product groups. /// </summary> /// <returns>List of product groups</returns> private IEnumerable <ProductGroup> GetProductGroups() { var list = new List <ProductGroup>(); list.Add(new ProductGroup { Id = 0, Name = "not selected" }); var di = this.Session["DisplayInfo"] as DisplayInfo; if (di != null) { IStoreDataSource ds = new StoreDataProvider(di.ConnStr); list.AddRange(ds.Groups()); return(list); } return(null); }
/// <summary> /// 设置数据提供者 /// </summary> /// <param name="context">数据安全上下文(注册成功后须使用此上下文才能进行私有数据更新)</param> /// <param name="provider">数据提供者</param> /// <returns></returns> public int SetDataProvider(int context, StoreDataProvider provider) { if (StoreDataProvider == null) { StoreDataProvider = provider; currentHolderContext = context; return(context); } else if (context != currentHolderContext) { GameErrorManager.SetLastErrorAndLog(GameError.ContextMismatch, "StoreData", "上下文 {0} 没有操作此数据的权限", context); return(0); } else { StoreDataProvider = provider; return(context); } }
/// <summary> /// Handles the Load event of the imageUpload control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void ImageUpload_Load(object sender, EventArgs e) { ////Get the required controls var imageUpload = sender as FileUpload; if (imageUpload == null) { return; } var parent = imageUpload.Parent; if (parent == null) { return; } var imageUploadStatus = parent.FindControl("imageUploadStatusLabel") as Label; if (imageUploadStatus == null) { return; } ////If a file is posted, save it if (this.IsPostBack) { if (imageUpload.PostedFile != null && imageUpload.PostedFile.ContentLength > 0) { try { var di = this.Session["DisplayInfo"] as DisplayInfo; if (di != null) { IStoreDataSource ds = new StoreDataProvider(di.ConnStr); var image = new byte[imageUpload.PostedFile.ContentLength]; var tmpImg = new byte[imageUpload.PostedFile.ContentLength]; imageUpload.PostedFile.InputStream.Read( image, 0, Convert.ToInt32(imageUpload.PostedFile.ContentLength)); if (image.SequenceEqual(tmpImg)) { return; } ds.SaveMedia(new MediaDraft { Media = image, FileSize = imageUpload.PostedFile.ContentLength, ServerFilePath = imageUpload.PostedFile.FileName }); } imageUploadStatus.Text = string.Format("Image {0} successfully uploaded!", imageUpload.PostedFile.FileName); } catch (Exception ex) { //// Logger.Log(ex.Message); imageUploadStatus.Text = string.Format("Error uploading {0}!", imageUpload.PostedFile.FileName); } } else { imageUploadStatus.Text = string.Empty; } } }