protected void rptLabels_ItemDataBound(object sender, RepeaterItemEventArgs e) { RepeaterItem item = e.Item; if (item.ItemIndex > -1 && item.DataItem is LabelBO) { LabelBO objLabel = (LabelBO)item.DataItem; string labelLocation = IndicoConfiguration.AppConfiguration.DataFolderName + "/Labels/" + objLabel.LabelImagePath; if (!File.Exists(IndicoConfiguration.AppConfiguration.PathToProjectFolder + "/" + labelLocation)) { labelLocation = IndicoConfiguration.AppConfiguration.DataFolderName + "/noimage-png-350px-350px.png"; } System.Drawing.Image VLOrigImage = System.Drawing.Image.FromFile(IndicoConfiguration.AppConfiguration.PathToProjectFolder + "\\" + labelLocation); SizeF origImageSize = VLOrigImage.PhysicalDimension; VLOrigImage.Dispose(); List <float> lstImgDimensions = (new ImageProcess()).GetResizedImageDimension(Convert.ToInt32(Math.Abs(origImageSize.Width)), Convert.ToInt32(Math.Abs(origImageSize.Height)), 210, 160); Label lblItemName = (Label)item.FindControl("lblItemName"); lblItemName.Text = objLabel.Name; System.Web.UI.WebControls.Image imgLabel = (System.Web.UI.WebControls.Image)item.FindControl("imgLabel"); imgLabel.ImageUrl = labelLocation; imgLabel.Width = int.Parse(lstImgDimensions[1].ToString()); imgLabel.Height = int.Parse(lstImgDimensions[0].ToString()); HyperLink linkDelete = (HyperLink)item.FindControl("linkDelete"); linkDelete.Attributes.Add("qid", objLabel.ID.ToString()); linkDelete.Visible = objLabel.DistributorLabelsWhereThisIsLabel.Any() || objLabel.OrderDetailsWhereThisIsLabel.Any(); LinkButton linkEdit = (LinkButton)item.FindControl("linkEdit"); linkEdit.Attributes.Add("qid", objLabel.ID.ToString()); var available = CheckLabelUsed((int)objLabel.ID); if (available) { var linkInactivate = (HyperLink)item.FindControl("linkInactivate"); linkInactivate.Attributes.Add("qid", objLabel.ID.ToString()); linkDelete.Visible = false; var labelActive = IsActiveLabel((int)objLabel.ID); if (labelActive) { linkInactivate.Visible = true; } else { var linkReactivate = (HyperLink)item.FindControl("linkReactivate"); linkReactivate.Attributes.Add("qid", objLabel.ID.ToString()); linkReactivate.Visible = true; } } HiddenField hdnLabelID = (HiddenField)item.FindControl("hdnLabelID"); hdnLabelID.Value = objLabel.ID.ToString(); } }
protected void rptLabels_ItemCommand(object source, RepeaterCommandEventArgs e) { try { HiddenField hdnLabelID = (HiddenField)e.Item.FindControl("hdnLabelID"); LabelBO objLabel = new LabelBO(); objLabel.ID = int.Parse(hdnLabelID.Value); objLabel.GetObject(); this.hdnEditLabel.Value = hdnLabelID.Value; this.txtLabelName.Text = objLabel.Name; this.chbIsSample.Checked = objLabel.IsSample; btnAddLabel.InnerText = "Update Label"; string labelLocation = IndicoConfiguration.AppConfiguration.DataFolderName + "/Labels/" + objLabel.LabelImagePath; if (!File.Exists(IndicoConfiguration.AppConfiguration.PathToProjectFolder + "/" + labelLocation)) { labelLocation = IndicoConfiguration.AppConfiguration.DataFolderName + "/noimage-png-350px-350px.png"; } System.Drawing.Image VLOrigImage = System.Drawing.Image.FromFile(IndicoConfiguration.AppConfiguration.PathToProjectFolder + "\\" + labelLocation); SizeF origImageSize = VLOrigImage.PhysicalDimension; VLOrigImage.Dispose(); List <float> lstImgDimensions = (new ImageProcess()).GetResizedImageDimension(Convert.ToInt32(Math.Abs(origImageSize.Width)), Convert.ToInt32(Math.Abs(origImageSize.Height)), 210, 160); //Label lblItemName = (Label)item.FindControl("lblItemName"); //lblItemName.Text = objLabel.Name; //System.Web.UI.WebControls.Image imgLabel = (System.Web.UI.WebControls.Image)e.Item.FindControl("imgLabel"); this.imgLabel.ImageUrl = labelLocation; this.imgLabel.Width = int.Parse(lstImgDimensions[1].ToString()); this.imgLabel.Height = int.Parse(lstImgDimensions[0].ToString()); this.imgLabel.Visible = true; } catch (Exception ex) { } }
private void ProcessForm() { string sourceFileLocation = string.Empty; string destinationFolderPath = string.Empty; string LabelName = this.hdnUploadFiles.Value.Split(',')[0]; int labelID = int.Parse(hdnEditLabel.Value); using (TransactionScope ts = new TransactionScope()) { try { if (this.chbIsSample.Checked) //Sample { LabelBO objLabel = new LabelBO(this.ObjContext); if (labelID > 0) { objLabel.ID = labelID; objLabel.GetObject(); } objLabel.IsSample = this.chbIsSample.Checked; objLabel.Name = this.txtLabelName.Text.Trim(); #region Copy File if (LabelName != string.Empty && LabelName != "0") { objLabel.LabelImagePath = LabelName; destinationFolderPath = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\Labels\\"; sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + LabelName; if (File.Exists(destinationFolderPath + "\\" + LabelName)) { string tmpFileName = Path.GetFileNameWithoutExtension(LabelName); string tmpExtension = Path.GetExtension(LabelName); LabelName = tmpFileName + "_" + (new Random()).Next(100).ToString() + tmpExtension; objLabel.LabelImagePath = LabelName; } if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); } File.Copy(sourceFileLocation, destinationFolderPath + "\\" + LabelName); } #endregion if (labelID == 0) { objLabel.Add(); } this.ObjContext.SaveChanges(); ts.Complete(); this.hdnUploadFiles.Value = "0"; } else { int selectedDistributor = int.Parse(this.ddlDistributor.SelectedValue); if (selectedDistributor > 0) { var newLabelName = txtLabelName.Text.Trim(); var available = CheckNameAvailable(selectedDistributor, newLabelName); if (!available) { nameExists.Visible = true; return; } CompanyBO objDistributor = new CompanyBO(this.ObjContext); objDistributor.ID = selectedDistributor; objDistributor.GetObject(); LabelBO objLabel = new LabelBO(this.ObjContext); if (labelID > 0) { objLabel.ID = labelID; objLabel.GetObject(); } objLabel.IsSample = this.chbIsSample.Checked; objLabel.Name = this.txtLabelName.Text.Trim(); #region Copy File if (LabelName != string.Empty && LabelName != "0") { objLabel.LabelImagePath = objDistributor.ID.ToString() + "/" + LabelName; destinationFolderPath = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\Labels\\" + objDistributor.ID.ToString(); sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + LabelName; if (File.Exists(destinationFolderPath + "\\" + LabelName)) { string tmpFileName = Path.GetFileNameWithoutExtension(LabelName); string tmpExtension = Path.GetExtension(LabelName); LabelName = tmpFileName + "_" + (new Random()).Next(100).ToString() + tmpExtension; objLabel.LabelImagePath = objDistributor.ID.ToString() + "/" + LabelName; } if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); } File.Copy(sourceFileLocation, destinationFolderPath + "\\" + LabelName); } #endregion if (labelID == 0) { objDistributor.DistributorLabelsWhereThisIsDistributor.Add(objLabel); } this.ObjContext.SaveChanges(); ts.Complete(); this.hdnUploadFiles.Value = "0"; } } ClearControls(); } catch (Exception ex) { IndicoLogging.log.Error("Error occured while adding labels", ex); } } }
protected void btnDelete_Click(object sender, EventArgs e) { int labelId = int.Parse(this.hdnSelectedId.Value); int distributorId = int.Parse(this.ddlDistributor.SelectedValue); if (labelId > 0 && distributorId > 0) { using (TransactionScope ts = new TransactionScope()) { try { CompanyBO objDistributor = new CompanyBO(this.ObjContext); objDistributor.ID = distributorId; objDistributor.GetObject(); LabelBO objLabel = new LabelBO(this.ObjContext); objLabel.ID = labelId; objLabel.GetObject(); string labelPath = objLabel.LabelImagePath; objLabel.DistributorLabelsWhereThisIsLabel.Remove(objDistributor); objLabel.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); string fileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\Labels\\" + labelPath; if (File.Exists(fileLocation)) { try { File.Delete(fileLocation); } catch { } } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while deleting the label", ex); } this.cvLabel.Enabled = false; this.rfvLabelName.Enabled = false; } } else if (labelId > 0) { using (TransactionScope ts = new TransactionScope()) { try { LabelBO objLabel = new LabelBO(this.ObjContext); objLabel.ID = labelId; objLabel.GetObject(); string labelPath = objLabel.LabelImagePath; objLabel.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); string fileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\Labels\\" + labelPath; if (File.Exists(fileLocation)) { try { File.Delete(fileLocation); } catch { } } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while deleting the label", ex); } this.rfvDistributor.Enabled = false; this.rfvLabelName.Enabled = false; this.cvLabel.Enabled = false; } } this.PopulateLabels(0); }