Int64 IHREmployeeDocumentDataAccess.Add(HREmployeeDocumentEntity hREmployeeDocumentEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(hREmployeeDocumentEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(hREmployeeDocumentEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private Int64 UpdateTran(HREmployeeDocumentEntity hREmployeeDocumentEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.HREmployeeDocument_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, "@EmployeeDocumentID", DbType.Int64, hREmployeeDocumentEntity.EmployeeDocumentID); db.AddInParameter(cmd, "@EmployeeID", DbType.Int64, hREmployeeDocumentEntity.EmployeeID); db.AddInParameter(cmd, "@DocumentCategoryID", DbType.Int64, hREmployeeDocumentEntity.DocumentCategoryID); db.AddInParameter(cmd, "@Extension", DbType.String, hREmployeeDocumentEntity.Extension); db.AddInParameter(cmd, "@Remarks", DbType.String, hREmployeeDocumentEntity.Remarks); db.AddInParameter(cmd, "@Path", DbType.String, hREmployeeDocumentEntity.Path); db.AddInParameter(cmd, "@OriginalFileName", DbType.String, hREmployeeDocumentEntity.OriginalFileName); db.AddInParameter(cmd, "@CurrentFileName", DbType.String, hREmployeeDocumentEntity.CurrentFileName); db.AddInParameter(cmd, "@FileType", DbType.String, hREmployeeDocumentEntity.FileType); 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); }
private void SaveHREmployeeDocumentEntity() { if (IsValid) { try { HREmployeeDocumentEntity hREmployeeDocumentEntity = BuildHREmployeeDocumentEntity(); Int64 result = -1; if (hREmployeeDocumentEntity.IsNew) { result = FCCHREmployeeDocument.GetFacadeCreate().Add(hREmployeeDocumentEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeDocumentEntity.FLD_NAME_EmployeeDocumentID, hREmployeeDocumentEntity.EmployeeDocumentID.ToString(), SQLMatchType.Equal); result = FCCHREmployeeDocument.GetFacadeCreate().Update(hREmployeeDocumentEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _EmployeeDocumentID = 0; _HREmployeeDocumentEntity = new HREmployeeDocumentEntity(); PrepareInitialView(); BindHREmployeeDocumentList(); if (hREmployeeDocumentEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Employee Document Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Employee Document Information has been updated successfully.", false); } } else { if (hREmployeeDocumentEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Employee Document Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Employee Document Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 DeleteTran(HREmployeeDocumentEntity hREmployeeDocumentEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.HREmployeeDocument_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 lvHREmployeeDocument_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 EmployeeDocumentID; Int64.TryParse(e.CommandArgument.ToString(), out EmployeeDocumentID); if (EmployeeDocumentID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _EmployeeDocumentID = EmployeeDocumentID; PrepareEditView(); } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(HREmployeeDocumentEntity.FLD_NAME_EmployeeDocumentID, EmployeeDocumentID.ToString(), SQLMatchType.Equal); HREmployeeDocumentEntity hREmployeeDocumentEntity = new HREmployeeDocumentEntity(); result = FCCHREmployeeDocument.GetFacadeCreate().Delete(hREmployeeDocumentEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _EmployeeDocumentID = 0; _HREmployeeDocumentEntity = new HREmployeeDocumentEntity(); PrepareInitialView(); BindHREmployeeDocumentList(); MiscUtil.ShowMessage(lblMessage, "Employee Document has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete Employee Document.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private Int64 Update(HREmployeeDocumentEntity hREmployeeDocumentEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.HREmployeeDocument_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@EmployeeDocumentID", DbType.Int64, hREmployeeDocumentEntity.EmployeeDocumentID); Database.AddInParameter(cmd, "@EmployeeID", DbType.Int64, hREmployeeDocumentEntity.EmployeeID); Database.AddInParameter(cmd, "@DocumentCategoryID", DbType.Int64, hREmployeeDocumentEntity.DocumentCategoryID); Database.AddInParameter(cmd, "@Extension", DbType.String, hREmployeeDocumentEntity.Extension); Database.AddInParameter(cmd, "@Remarks", DbType.String, hREmployeeDocumentEntity.Remarks); Database.AddInParameter(cmd, "@Path", DbType.String, hREmployeeDocumentEntity.Path); Database.AddInParameter(cmd, "@OriginalFileName", DbType.String, hREmployeeDocumentEntity.OriginalFileName); Database.AddInParameter(cmd, "@CurrentFileName", DbType.String, hREmployeeDocumentEntity.CurrentFileName); Database.AddInParameter(cmd, "@FileType", DbType.String, hREmployeeDocumentEntity.FileType); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("HREmployeeDocumentEntity already exists. Please specify another HREmployeeDocumentEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("HREmployeeDocumentEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("HREmployeeDocumentEntity already exists. Please specify another HREmployeeDocumentEntity."); } } } } return(returnCode); }
private Int64 Delete(HREmployeeDocumentEntity hREmployeeDocumentEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.HREmployeeDocument_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("HREmployeeDocumentEntity already exists. Please specify another HREmployeeDocumentEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("HREmployeeDocumentEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("HREmployeeDocumentEntity already exists. Please specify another HREmployeeDocumentEntity."); } } } } return(returnCode); }
private void PrepareEditView() { HREmployeeDocumentEntity hREmployeeDocumentEntity = CurrentHREmployeeDocumentEntity; if (!hREmployeeDocumentEntity.IsNew) { if (ddlDocumentCategoryID.Items.Count > 0 && hREmployeeDocumentEntity.DocumentCategoryID != null) { ddlDocumentCategoryID.SelectedValue = hREmployeeDocumentEntity.DocumentCategoryID.ToString(); } //txtExtension.Text = hREmployeeDocumentEntity.Extension.ToString(); txtRemarks.Text = hREmployeeDocumentEntity.Remarks.ToString(); //txtPath.Text = hREmployeeDocumentEntity.Path.ToString(); //txtOriginalFileName.Text = hREmployeeDocumentEntity.OriginalFileName.ToString(); //txtCurrentFileName.Text = hREmployeeDocumentEntity.CurrentFileName.ToString(); //txtFileType.Text = hREmployeeDocumentEntity.FileType.ToString(); btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
protected void btnAddNew_Click(object sender, EventArgs e) { _EmployeeDocumentID = 0; _HREmployeeDocumentEntity = new HREmployeeDocumentEntity(); PrepareInitialView(); }
private HREmployeeDocumentEntity BuildHREmployeeDocumentEntity() { HREmployeeDocumentEntity hREmployeeDocumentEntity = CurrentHREmployeeDocumentEntity; hREmployeeDocumentEntity.EmployeeID = OverviewEmployeeID; if (ddlDocumentCategoryID.Items.Count > 0) { if (ddlDocumentCategoryID.SelectedValue == "0") { } else { hREmployeeDocumentEntity.DocumentCategoryID = Int64.Parse(ddlDocumentCategoryID.SelectedValue); } } //hREmployeeDocumentEntity.Extension = txtExtension.Text.Trim(); hREmployeeDocumentEntity.Remarks = txtRemarks.Text.Trim(); //hREmployeeDocumentEntity.Path = txtPath.Text.Trim(); //hREmployeeDocumentEntity.OriginalFileName = txtOriginalFileName.Text.Trim(); //hREmployeeDocumentEntity.CurrentFileName = txtCurrentFileName.Text.Trim(); //hREmployeeDocumentEntity.FileType = txtFileType.Text.Trim(); #region File String Urlpath; if (fuFileUploadUrl.HasFile == true && hREmployeeDocumentEntity.Path.IsNotNullOrEmpty()) { if (File.Exists(Server.MapPath(hREmployeeDocumentEntity.Path))) { File.Delete(Server.MapPath(hREmployeeDocumentEntity.Path)); } Urlpath = FileUploadConstants.HR.EmployeeDocument + Guid.NewGuid() + fuFileUploadUrl.FileName; fuFileUploadUrl.SaveAs(Server.MapPath(Urlpath)); hREmployeeDocumentEntity.Path = Urlpath; } if (hREmployeeDocumentEntity.Path.IsNotNullOrEmpty() && fuFileUploadUrl.HasFile == false) { hREmployeeDocumentEntity.Path = hREmployeeDocumentEntity.Path; } if (fuFileUploadUrl.HasFile == false && hREmployeeDocumentEntity.Path.IsNullOrEmpty()) { hREmployeeDocumentEntity.Path = null; } if (fuFileUploadUrl.HasFile == true && hREmployeeDocumentEntity.Path.IsNullOrEmpty()) { Urlpath = FileUploadConstants.HR.EmployeeDocument + Guid.NewGuid() + fuFileUploadUrl.FileName; fuFileUploadUrl.SaveAs(Server.MapPath(Urlpath)); hREmployeeDocumentEntity.Path = Urlpath; } hREmployeeDocumentEntity.OriginalFileName = Path.GetFileName(fuFileUploadUrl.FileName); hREmployeeDocumentEntity.CurrentFileName = Guid.NewGuid().ToString() + Path.GetExtension(fuFileUploadUrl.FileName); hREmployeeDocumentEntity.FileType = ""; hREmployeeDocumentEntity.Extension = Path.GetExtension(fuFileUploadUrl.FileName); //hREmployeeDocumentEntity.Path = FileUploadConstants.HR.EmployeeDocument + hREmployeeDocumentEntity.CurrentFileName; //hREmployeeDocumentEntity.Remarks = String.Empty; #endregion File return(hREmployeeDocumentEntity); }
Int64 IHREmployeeDocumentFacade.Delete(HREmployeeDocumentEntity hREmployeeDocumentEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateHREmployeeDocumentDataAccess().Delete(hREmployeeDocumentEntity, filterExpression, option, reqTran)); }
Int64 IHREmployeeDocumentFacade.Add(HREmployeeDocumentEntity hREmployeeDocumentEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateHREmployeeDocumentDataAccess().Add(hREmployeeDocumentEntity, option, reqTran)); }