/// <summary> /// Process the page data. /// </summary> private void ProcessForm(int itemId) { try { using (TransactionScope ts = new TransactionScope()) { ItemBO objItemSubCategoryBO = new ItemBO(this.ObjContext); if (itemId > 0) { objItemSubCategoryBO.ID = itemId; objItemSubCategoryBO.GetObject(); } objItemSubCategoryBO.Parent = int.Parse(this.ddlItem.SelectedValue); objItemSubCategoryBO.Name = this.txtName.Text; objItemSubCategoryBO.Description = this.txtDescription.Text; if (itemId == 0) { objItemSubCategoryBO.Add(); } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error //IndicoLogging.log("Error occured while Adding the Item", ex); } }
/// <summary> /// Process the page data. /// </summary> /// /*private void ProcessForm(int queryId, bool isDelete) * { * try * { * using (TransactionScope ts = new TransactionScope()) * { * ItemBO objItem = new ItemBO(this.ObjContext); * if (queryId > 0) * { * objItem.ID = queryId; * objItem.GetObject(); * } * * if (isDelete) * { * objItem.Delete(); * } * else * { * objItem.Name = this.txtItemName.Text; * objItem.Description = this.txtDescription.Text; * objItem.Parent = int.Parse(this.ddlParentAttribute.SelectedItem.Value); * if (queryId == 0) * { * objItem.Add(); * } * } * #region ItemMeasurementGuideImages * * if (this.hdnItemImage.Value != "0") * { * try * { * int n = 0; * * foreach (string fileName in this.hdnItemImage.Value.Split('|').Select(o => o.Split(',')[0])) * { * if (fileName != string.Empty) * { * n++; * ItemMeasurementGuideImageBO objItemMeasurementImage = new ItemMeasurementGuideImageBO(this.ObjContext); * objItemMeasurementImage.Size = (int)(new FileInfo(IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileName)).Length; * objItemMeasurementImage.Filename = Path.GetFileNameWithoutExtension(fileName); * objItemMeasurementImage.Extension = Path.GetExtension(fileName); * objItem.ItemMeasurementGuideImagesWhereThisIsItem.Add(objItemMeasurementImage); * } * } * } * catch (Exception ex) * { * IndicoLogging.log.Error("Error occured while saving ItemMeasureMentGuideImage", ex); * } * } * #endregion * * this.ObjContext.SaveChanges(); * ts.Complete(); * #region Copy ItemMeasureMentGuideImage * * string sourceFileLocation = string.Empty; * string destinationFolderPath = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\ItemMeasurementGuideImages\\" + objItem.ID.ToString(); * * foreach (string fileName in this.hdnItemImage.Value.Split('|').Select(o => o.Split(',')[0])) * { * sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileName; * * if (fileName != string.Empty) * { * if (File.Exists(destinationFolderPath + "\\" + fileName)) * { * File.Delete(destinationFolderPath + "\\" + fileName); * } * else * { * if (!Directory.Exists(destinationFolderPath)) * Directory.CreateDirectory(destinationFolderPath); * File.Copy(sourceFileLocation, destinationFolderPath + "\\" + fileName); * } * } * } * #endregion * } * } * catch (Exception ex) * { * // Log the error * //IndicoLogging.log("Error occured while Adding the Item", ex); * } * }*/ private void ProcessItems(bool isNewItem, bool isSubItem) { try { using (TransactionScope ts = new TransactionScope()) { ItemBO objItem = new ItemBO(this.ObjContext); if (!isNewItem) { objItem.ID = int.Parse(this.hdnSelectedItemID.Value); objItem.GetObject(); } if (isSubItem) { objItem.Parent = int.Parse(this.ddlParentAttribute.SelectedValue); } else { #region ItemMeasurementGuideImages if (this.hdnItemImage.Value != "0") { try { int n = 0; foreach (string fileName in this.hdnItemImage.Value.Split('|').Select(o => o.Split(',')[0])) { if (fileName != string.Empty) { n++; ItemMeasurementGuideImageBO objItemMeasurementImage = new ItemMeasurementGuideImageBO(this.ObjContext); objItemMeasurementImage.Size = (int)(new FileInfo(IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileName)).Length; objItemMeasurementImage.Filename = Path.GetFileNameWithoutExtension(fileName); objItemMeasurementImage.Extension = Path.GetExtension(fileName); objItem.ItemMeasurementGuideImagesWhereThisIsItem.Add(objItemMeasurementImage); } } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while saving ItemMeasureMentGuideImage", ex); } } #endregion } objItem.Name = (!isSubItem) ? this.txtItemName.Text : this.hdnSubItemName.Value.ToString(); objItem.ItemType = int.Parse(this.ddlItemType.SelectedValue); objItem.Description = (!isSubItem) ? this.txtDescription.Text : this.hdnSubItemDescription.Value.ToString(); if (isNewItem) { objItem.Add(); } this.ObjContext.SaveChanges(); ts.Complete(); #region Copy ItemMeasureMentGuideImage if (!isSubItem) { string sourceFileLocation = string.Empty; string destinationFolderPath = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\ItemMeasurementGuideImages\\" + objItem.ID.ToString(); foreach (string fileName in this.hdnItemImage.Value.Split('|').Select(o => o.Split(',')[0])) { sourceFileLocation = IndicoConfiguration.AppConfiguration.PathToDataFolder + "\\temp\\" + fileName; if (fileName != string.Empty) { if (File.Exists(destinationFolderPath + "\\" + fileName)) { File.Delete(destinationFolderPath + "\\" + fileName); } else { if (!Directory.Exists(destinationFolderPath)) { Directory.CreateDirectory(destinationFolderPath); } File.Copy(sourceFileLocation, destinationFolderPath + "\\" + fileName); } } } } #endregion } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while processing Item", ex); } }