protected void lvCMNDashboardItem_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 DashboardItemID; Int64.TryParse(e.CommandArgument.ToString(), out DashboardItemID); if (DashboardItemID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _DashboardItemID = DashboardItemID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(CMNDashboardItemEntity.FLD_NAME_DashboardItemID, DashboardItemID.ToString(), SQLMatchType.Equal); CMNDashboardItemEntity cMNDashboardItemEntity = FCCCMNDashboardItem.GetFacadeCreate().GetByID(DashboardItemID); result = FCCCMNDashboardItem.GetFacadeCreate().Delete(cMNDashboardItemEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { if (File.Exists(Server.MapPath(cMNDashboardItemEntity.ImageUrl))) { File.Delete(Server.MapPath(cMNDashboardItemEntity.ImageUrl)); } if (File.Exists(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl))) { File.Delete(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl)); } _DashboardItemID = 0; _CMNDashboardItemEntity = new CMNDashboardItemEntity(); PrepareInitialView(); BindCMNDashboardItemList(); MiscUtil.ShowMessage(lblMessage, "Dashboard Item has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete Dashboard Item.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
Int64 ICMNDashboardItemDataAccess.Add(CMNDashboardItemEntity cMNDashboardItemEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(cMNDashboardItemEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(cMNDashboardItemEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private void PrepareEditView() { CMNDashboardItemEntity cMNDashboardItemEntity = CurrentCMNDashboardItemEntity; if (!cMNDashboardItemEntity.IsNew) { if (ddlParentDashboardItemID.Items.Count > 0 && cMNDashboardItemEntity.ParentDashboardItemID != null) { ddlParentDashboardItemID.SelectedValue = cMNDashboardItemEntity.ParentDashboardItemID.ToString(); } if (ddlParentDashboardItemID.Items.Count > 0 && !cMNDashboardItemEntity.ParentDashboardItemID.HasValue) { ddlParentDashboardItemID.SelectedValue = "0"; } txtTitle.Text = cMNDashboardItemEntity.Title.ToString(); txtTittleColor.Text = cMNDashboardItemEntity.TittleColor.ToString(); txtDescription.Text = cMNDashboardItemEntity.Description.ToString(); txtDescriptionColor.Text = cMNDashboardItemEntity.DescriptionColor.ToString(); txtNavigationUrl.Text = cMNDashboardItemEntity.NavigationUrl.ToString(); chkIsPopup.Checked = cMNDashboardItemEntity.IsPopup; txtHoverMessage.Text = cMNDashboardItemEntity.HoverMessage.ToString(); txtSequenceID.Text = CurrentCMNDashboardItemEntity.SequenceID.ToString(); txtImageWidth.Text = cMNDashboardItemEntity.ImageWidth.ToString(); txtImageHeight.Text = cMNDashboardItemEntity.ImageHeight.ToString(); txtDashboardItemWidth.Text = cMNDashboardItemEntity.DashboardItemWidth.ToString(); txtDashboardItemHeight.Text = cMNDashboardItemEntity.DashboardItemHeight.ToString(); chkIsRemoved.Checked = cMNDashboardItemEntity.IsRemoved; rfvImageUrl.Enabled = false; btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
private Int64 Update(CMNDashboardItemEntity cMNDashboardItemEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CMNDashboardItem_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@DashboardItemID", DbType.Int64, cMNDashboardItemEntity.DashboardItemID); Database.AddInParameter(cmd, "@ParentDashboardItemID", DbType.Int64, cMNDashboardItemEntity.ParentDashboardItemID); Database.AddInParameter(cmd, "@Title", DbType.String, cMNDashboardItemEntity.Title); Database.AddInParameter(cmd, "@TittleColor", DbType.String, cMNDashboardItemEntity.TittleColor); Database.AddInParameter(cmd, "@Description", DbType.String, cMNDashboardItemEntity.Description); Database.AddInParameter(cmd, "@DescriptionColor", DbType.String, cMNDashboardItemEntity.DescriptionColor); Database.AddInParameter(cmd, "@ImageUrl", DbType.String, cMNDashboardItemEntity.ImageUrl); Database.AddInParameter(cmd, "@HoverImageUrl", DbType.String, cMNDashboardItemEntity.HoverImageUrl); Database.AddInParameter(cmd, "@NavigationUrl", DbType.String, cMNDashboardItemEntity.NavigationUrl); Database.AddInParameter(cmd, "@IsPopup", DbType.Boolean, cMNDashboardItemEntity.IsPopup); Database.AddInParameter(cmd, "@HoverMessage", DbType.String, cMNDashboardItemEntity.HoverMessage); Database.AddInParameter(cmd, "@SequenceID", DbType.Int32, cMNDashboardItemEntity.SequenceID); Database.AddInParameter(cmd, "@ImageWidth", DbType.Int32, cMNDashboardItemEntity.ImageWidth); Database.AddInParameter(cmd, "@ImageHeight", DbType.Int32, cMNDashboardItemEntity.ImageHeight); Database.AddInParameter(cmd, "@DashboardItemWidth", DbType.Int32, cMNDashboardItemEntity.DashboardItemWidth); Database.AddInParameter(cmd, "@DashboardItemHeight", DbType.Int32, cMNDashboardItemEntity.DashboardItemHeight); Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, cMNDashboardItemEntity.IsRemoved); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CMNDashboardItemEntity already exists. Please specify another CMNDashboardItemEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CMNDashboardItemEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CMNDashboardItemEntity already exists. Please specify another CMNDashboardItemEntity."); } } } } return(returnCode); }
private void SaveCMNDashboardItemEntity() { if (IsValid) { try { CMNDashboardItemEntity cMNDashboardItemEntity = BuildCMNDashboardItemEntity(); Int64 result = -1; if (cMNDashboardItemEntity.IsNew) { result = FCCCMNDashboardItem.GetFacadeCreate().Add(cMNDashboardItemEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CMNDashboardItemEntity.FLD_NAME_DashboardItemID, cMNDashboardItemEntity.DashboardItemID.ToString(), SQLMatchType.Equal); result = FCCCMNDashboardItem.GetFacadeCreate().Update(cMNDashboardItemEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _DashboardItemID = 0; _CMNDashboardItemEntity = new CMNDashboardItemEntity(); PrepareInitialView(); BindCMNDashboardItemList(); if (cMNDashboardItemEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Dashboard Item Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Dashboard Item Information has been updated successfully.", false); } } else { if (cMNDashboardItemEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Dashboard Item Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Dashboard Item Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
protected void lvCMNDashboardItem_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 DashboardItemID; Int64.TryParse(e.CommandArgument.ToString(), out DashboardItemID); if (DashboardItemID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _DashboardItemID = DashboardItemID; PrepareEditView(); } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(CMNDashboardItemEntity.FLD_NAME_DashboardItemID, DashboardItemID.ToString(), SQLMatchType.Equal); CMNDashboardItemEntity cMNDashboardItemEntity = FCCCMNDashboardItem.GetFacadeCreate().GetByID(DashboardItemID); result = FCCCMNDashboardItem.GetFacadeCreate().Delete(cMNDashboardItemEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { if (File.Exists(Server.MapPath(cMNDashboardItemEntity.ImageUrl))) { File.Delete(Server.MapPath(cMNDashboardItemEntity.ImageUrl)); } if (File.Exists(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl))) { File.Delete(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl)); } _DashboardItemID = 0; _CMNDashboardItemEntity = new CMNDashboardItemEntity(); PrepareInitialView(); } else { } } catch (Exception ex) { } } } }
private Int64 DeleteTran(CMNDashboardItemEntity cMNDashboardItemEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CMNDashboardItem_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode >= 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
protected void lvCMNDashboardItem_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; CMNDashboardItemEntity ent = (CMNDashboardItemEntity)dataItem.DataItem; HyperLink hypImgDashBoardItem = (HyperLink)e.Item.FindControl("hypImgDashBoardItem"); hypImgDashBoardItem.NavigateUrl = UrlHelper.BuildSecureUrl((String)DataBinder.Eval(e.Item.DataItem, "NavigationUrl"), string.Empty, UrlConstants.OVERVIEW_DASHBOARD_ITEM_ID, ent.DashboardItemID.ToString()).ToString(); HyperLink hypDashBoardItem = (HyperLink)e.Item.FindControl("hypDashBoardItem"); hypDashBoardItem.NavigateUrl = UrlHelper.BuildSecureUrl((String)DataBinder.Eval(e.Item.DataItem, "NavigationUrl"), string.Empty, UrlConstants.OVERVIEW_DASHBOARD_ITEM_ID, ent.DashboardItemID.ToString()).ToString(); ListView lvCMNDashboardItemQuicklink = (ListView)e.Item.FindControl("lvCMNDashboardItemQuicklink"); String fe = SqlExpressionBuilder.PrepareFilterExpression(CMNDashboardItemQuicklinkEntity.FLD_NAME_DashboardItemID, ent.DashboardItemID.ToString(), SQLMatchType.Equal); lvCMNDashboardItemQuicklink.DataSource = FCCCMNDashboardItemQuicklink.GetFacadeCreate().GetIL(null, null, String.Empty, fe, DatabaseOperationType.LoadWithFilterExpression); lvCMNDashboardItemQuicklink.DataBind(); } }
private Int64 Delete(CMNDashboardItemEntity cMNDashboardItemEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CMNDashboardItem_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("CMNDashboardItemEntity already exists. Please specify another CMNDashboardItemEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("CMNDashboardItemEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("CMNDashboardItemEntity already exists. Please specify another CMNDashboardItemEntity."); } } } } return(returnCode); }
private Int64 UpdateTran(CMNDashboardItemEntity cMNDashboardItemEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.CMNDashboardItem_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option, db); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); db.AddInParameter(cmd, "@DashboardItemID", DbType.Int64, cMNDashboardItemEntity.DashboardItemID); db.AddInParameter(cmd, "@ParentDashboardItemID", DbType.Int64, cMNDashboardItemEntity.ParentDashboardItemID); db.AddInParameter(cmd, "@Title", DbType.String, cMNDashboardItemEntity.Title); db.AddInParameter(cmd, "@TittleColor", DbType.String, cMNDashboardItemEntity.TittleColor); db.AddInParameter(cmd, "@Description", DbType.String, cMNDashboardItemEntity.Description); db.AddInParameter(cmd, "@DescriptionColor", DbType.String, cMNDashboardItemEntity.DescriptionColor); db.AddInParameter(cmd, "@ImageUrl", DbType.String, cMNDashboardItemEntity.ImageUrl); db.AddInParameter(cmd, "@HoverImageUrl", DbType.String, cMNDashboardItemEntity.HoverImageUrl); db.AddInParameter(cmd, "@NavigationUrl", DbType.String, cMNDashboardItemEntity.NavigationUrl); db.AddInParameter(cmd, "@IsPopup", DbType.Boolean, cMNDashboardItemEntity.IsPopup); db.AddInParameter(cmd, "@HoverMessage", DbType.String, cMNDashboardItemEntity.HoverMessage); db.AddInParameter(cmd, "@SequenceID", DbType.Int32, cMNDashboardItemEntity.SequenceID); db.AddInParameter(cmd, "@ImageWidth", DbType.Int32, cMNDashboardItemEntity.ImageWidth); db.AddInParameter(cmd, "@ImageHeight", DbType.Int32, cMNDashboardItemEntity.ImageHeight); db.AddInParameter(cmd, "@DashboardItemWidth", DbType.Int32, cMNDashboardItemEntity.DashboardItemWidth); db.AddInParameter(cmd, "@DashboardItemHeight", DbType.Int32, cMNDashboardItemEntity.DashboardItemHeight); db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, cMNDashboardItemEntity.IsRemoved); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode > 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
protected void btnAddNew_Click(object sender, EventArgs e) { _DashboardItemID = 0; _CMNDashboardItemEntity = new CMNDashboardItemEntity(); PrepareInitialView(); }
private CMNDashboardItemEntity BuildCMNDashboardItemEntity() { CMNDashboardItemEntity cMNDashboardItemEntity = CurrentCMNDashboardItemEntity; if (ddlParentDashboardItemID.Items.Count > 0) { if (ddlParentDashboardItemID.SelectedValue == "0") { cMNDashboardItemEntity.ParentDashboardItemID = null; } else { cMNDashboardItemEntity.ParentDashboardItemID = Int64.Parse(ddlParentDashboardItemID.SelectedValue); } } cMNDashboardItemEntity.Title = txtTitle.Text.Trim(); cMNDashboardItemEntity.TittleColor = txtTittleColor.Text.Trim(); cMNDashboardItemEntity.Description = txtDescription.Text.Trim(); cMNDashboardItemEntity.DescriptionColor = txtDescriptionColor.Text.Trim(); #region File Upload Manipulation if (fuImageUrl.HasFile == true && cMNDashboardItemEntity.ImageUrl.IsNotNullOrEmpty()) { if (File.Exists(Server.MapPath(CurrentCMNDashboardItemEntity.ImageUrl))) { File.Delete(Server.MapPath(CurrentCMNDashboardItemEntity.ImageUrl)); } String ImageUrlpath; ImageUrlpath = FileUploadConstants.DashboardItem.DashboardItemImageUrl + Guid.NewGuid() + fuImageUrl.FileName; fuImageUrl.SaveAs(Server.MapPath(ImageUrlpath)); cMNDashboardItemEntity.ImageUrl = ImageUrlpath; } if (fuImageUrl.HasFile == false && cMNDashboardItemEntity.ImageUrl.IsNotNullOrEmpty()) { cMNDashboardItemEntity.ImageUrl = cMNDashboardItemEntity.ImageUrl; } if (fuImageUrl.HasFile == true && cMNDashboardItemEntity.ImageUrl.IsNullOrEmpty()) { String ImageUrlpath; ImageUrlpath = FileUploadConstants.DashboardItem.DashboardItemImageUrl + Guid.NewGuid() + fuImageUrl.FileName; fuImageUrl.SaveAs(Server.MapPath(ImageUrlpath)); cMNDashboardItemEntity.ImageUrl = ImageUrlpath; } String HoverImageUrlpath; if (fuHoverImageUrl.HasFile == true && cMNDashboardItemEntity.HoverImageUrl.IsNotNullOrEmpty()) { if (File.Exists(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl))) { File.Delete(Server.MapPath(cMNDashboardItemEntity.HoverImageUrl)); } HoverImageUrlpath = FileUploadConstants.DashboardItem.DashboardItemHoverImageUrl + Guid.NewGuid() + fuHoverImageUrl.FileName; fuHoverImageUrl.SaveAs(Server.MapPath(HoverImageUrlpath)); cMNDashboardItemEntity.HoverImageUrl = HoverImageUrlpath; } if (cMNDashboardItemEntity.HoverImageUrl.IsNotNullOrEmpty() && fuHoverImageUrl.HasFile == false) { cMNDashboardItemEntity.HoverImageUrl = cMNDashboardItemEntity.HoverImageUrl; } if (fuHoverImageUrl.HasFile == false && cMNDashboardItemEntity.HoverImageUrl.IsNullOrEmpty()) { cMNDashboardItemEntity.HoverImageUrl = null; } if (fuHoverImageUrl.HasFile == true && cMNDashboardItemEntity.HoverImageUrl.IsNullOrEmpty()) { HoverImageUrlpath = FileUploadConstants.DashboardItem.DashboardItemHoverImageUrl + Guid.NewGuid() + fuHoverImageUrl.FileName; fuHoverImageUrl.SaveAs(Server.MapPath(HoverImageUrlpath)); cMNDashboardItemEntity.HoverImageUrl = HoverImageUrlpath; } #endregion cMNDashboardItemEntity.NavigationUrl = txtNavigationUrl.Text.Trim(); cMNDashboardItemEntity.IsPopup = chkIsPopup.Checked; cMNDashboardItemEntity.HoverMessage = txtHoverMessage.Text.Trim(); //Save Sequence ID if (_DashboardItemID > 0 && ddlParentDashboardItemID.SelectedValue == CurrentCMNDashboardItemEntity.SequenceID.ToString()) { cMNDashboardItemEntity.SequenceID = CurrentCMNDashboardItemEntity.SequenceID; } else { if (!txtSequenceID.Text.Trim().IsNullOrEmpty()) { cMNDashboardItemEntity.SequenceID = Int32.Parse(txtSequenceID.Text.Trim()); } } if (!txtImageWidth.Text.Trim().IsNullOrEmpty()) { cMNDashboardItemEntity.ImageWidth = Int32.Parse(txtImageWidth.Text.Trim()); } if (!txtImageHeight.Text.Trim().IsNullOrEmpty()) { cMNDashboardItemEntity.ImageHeight = Int32.Parse(txtImageHeight.Text.Trim()); } if (!txtDashboardItemWidth.Text.Trim().IsNullOrEmpty()) { cMNDashboardItemEntity.DashboardItemWidth = Int32.Parse(txtDashboardItemWidth.Text.Trim()); } if (!txtDashboardItemHeight.Text.Trim().IsNullOrEmpty()) { cMNDashboardItemEntity.DashboardItemHeight = Int32.Parse(txtDashboardItemHeight.Text.Trim()); } cMNDashboardItemEntity.IsRemoved = chkIsRemoved.Checked; return(cMNDashboardItemEntity); }
Int64 ICMNDashboardItemFacade.Delete(CMNDashboardItemEntity cMNDashboardItemEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCMNDashboardItemDataAccess().Delete(cMNDashboardItemEntity, filterExpression, option, reqTran)); }
Int64 ICMNDashboardItemFacade.Add(CMNDashboardItemEntity cMNDashboardItemEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateCMNDashboardItemDataAccess().Add(cMNDashboardItemEntity, option, reqTran)); }