Int64 ICMContractorLicenceDataAccess.Add(CMContractorLicenceEntity cMContractorLicenceEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(cMContractorLicenceEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(cMContractorLicenceEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private CMContractorLicenceEntity BuildCMContractorLicenceEntity()
        {
            CMContractorLicenceEntity cMContractorLicenceEntity = CurrentCMContractorLicenceEntity;

            cMContractorLicenceEntity.ContractorID = this.OverviewContractorID;
            cMContractorLicenceEntity.LicenceNo    = txtLicenceNo.Text.Trim();

            return(cMContractorLicenceEntity);
        }
        private void SaveCMContractorLicenceEntity()
        {
            if (IsValid)
            {
                try
                {
                    CMContractorLicenceEntity cMContractorLicenceEntity = BuildCMContractorLicenceEntity();

                    Int64 result = -1;

                    if (cMContractorLicenceEntity.IsNew)
                    {
                        result = FCCCMContractorLicence.GetFacadeCreate().Add(cMContractorLicenceEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CMContractorLicenceEntity.FLD_NAME_ContractorLicenceID, cMContractorLicenceEntity.ContractorLicenceID.ToString(), SQLMatchType.Equal);
                        result = FCCCMContractorLicence.GetFacadeCreate().Update(cMContractorLicenceEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _ContractorLicenceID       = 0;
                        _CMContractorLicenceEntity = new CMContractorLicenceEntity();
                        PrepareInitialView();
                        BindCMContractorLicenceList();

                        if (cMContractorLicenceEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Contractor Licence Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Contractor Licence Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (cMContractorLicenceEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Contractor Licence Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Contractor Licence Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        private Int64 UpdateTran(CMContractorLicenceEntity cMContractorLicenceEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CMContractorLicence_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, "@ContractorLicenceID", DbType.Int64, cMContractorLicenceEntity.ContractorLicenceID);
                db.AddInParameter(cmd, "@ContractorID", DbType.Int64, cMContractorLicenceEntity.ContractorID);
                db.AddInParameter(cmd, "@LicenceNo", DbType.String, cMContractorLicenceEntity.LicenceNo);

                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 PrepareEditView()
        {
            CMContractorLicenceEntity cMContractorLicenceEntity = CurrentCMContractorLicenceEntity;


            if (!cMContractorLicenceEntity.IsNew)
            {
                txtLicenceNo.Text = cMContractorLicenceEntity.LicenceNo.ToString();

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        protected void lvCMContractorLicence_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 ContractorLicenceID;

            Int64.TryParse(e.CommandArgument.ToString(), out ContractorLicenceID);

            if (ContractorLicenceID > 0)
            {
                if (string.Equals(e.CommandName, "EditItem"))
                {
                    _ContractorLicenceID = ContractorLicenceID;

                    PrepareEditView();

                    cpeEditor.Collapsed   = false;
                    cpeEditor.ClientState = "false";
                }
                else if (string.Equals(e.CommandName, "DeleteItem"))
                {
                    try
                    {
                        Int64 result = -1;

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(CMContractorLicenceEntity.FLD_NAME_ContractorLicenceID, ContractorLicenceID.ToString(), SQLMatchType.Equal);

                        CMContractorLicenceEntity cMContractorLicenceEntity = new CMContractorLicenceEntity();


                        result = FCCCMContractorLicence.GetFacadeCreate().Delete(cMContractorLicenceEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _ContractorLicenceID       = 0;
                            _CMContractorLicenceEntity = new CMContractorLicenceEntity();
                            PrepareInitialView();
                            BindCMContractorLicenceList();

                            MiscUtil.ShowMessage(lblMessage, "Contractor Licence has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete Contractor Licence.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 Update(CMContractorLicenceEntity cMContractorLicenceEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CMContractorLicence_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);

                Database.AddInParameter(cmd, "@ContractorLicenceID", DbType.Int64, cMContractorLicenceEntity.ContractorLicenceID);
                Database.AddInParameter(cmd, "@ContractorID", DbType.Int64, cMContractorLicenceEntity.ContractorID);
                Database.AddInParameter(cmd, "@LicenceNo", DbType.String, cMContractorLicenceEntity.LicenceNo);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("CMContractorLicenceEntity already exists. Please specify another CMContractorLicenceEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("CMContractorLicenceEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("CMContractorLicenceEntity already exists. Please specify another CMContractorLicenceEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _ContractorLicenceID       = 0;
     _CMContractorLicenceEntity = new CMContractorLicenceEntity();
     PrepareInitialView();
 }
 Int64 ICMContractorLicenceFacade.Delete(CMContractorLicenceEntity cMContractorLicenceEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCMContractorLicenceDataAccess().Delete(cMContractorLicenceEntity, filterExpression, option, reqTran));
 }
 Int64 ICMContractorLicenceFacade.Add(CMContractorLicenceEntity cMContractorLicenceEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCMContractorLicenceDataAccess().Add(cMContractorLicenceEntity, option, reqTran));
 }