コード例 #1
0
        public static BasicEntity GetEmployeesList(Model.GetEmployeesList data, Output.GetEmployeesList obj)
        {
            var retVal = new BasicEntity();

            retVal.AddParameter("@id", data.ID);
            retVal.AddParameter("@NIK", data.NIK);
            data.SqlDetail = retVal.SQLCommandBuilder("spEmployeeList");

            using (SqlDataReader reader = retVal.ExecReader())
            {
                while (reader.Read())
                {
                    obj.ResultCode    = (reader.IsDBNull(0)) ? 0 : reader.GetInt32(0);
                    obj.ErrorMessage  = (reader.IsDBNull(1)) ? string.Empty : reader.GetString(1);
                    retVal.ResultCode = obj.ResultCode;
                }

                if (retVal.ResultCode == 1)
                {
                    reader.NextResult();
                    while (reader.Read())
                    {
                        var item = new Output.GetEmployeesListData();

                        item.NIK          = (reader.IsDBNull(0)) ? string.Empty : reader.GetString(0);
                        item.FirstName    = (reader.IsDBNull(1)) ? string.Empty : reader.GetString(1);
                        item.LastName     = (reader.IsDBNull(2)) ? string.Empty : reader.GetString(2);
                        item.Gender       = (reader.IsDBNull(3)) ? string.Empty : reader.GetString(3);
                        item.Address      = (reader.IsDBNull(4)) ? string.Empty : reader.GetString(4);
                        item.PlaceOfBirth = (reader.IsDBNull(5)) ? string.Empty : reader.GetString(5);
                        item.DateOfBirth  = (reader.IsDBNull(6)) ? DateTime.MinValue : reader.GetDateTime(6);
                        item.Email        = (reader.IsDBNull(7)) ? string.Empty : reader.GetString(7);
                        item.Phone        = (reader.IsDBNull(8)) ? string.Empty : reader.GetString(8);
                        item.JobTitleID   = (reader.IsDBNull(9)) ? 0 : reader.GetInt32(9);
                        item.HireDate     = (reader.IsDBNull(10)) ? DateTime.MinValue : reader.GetDateTime(10);

                        obj.Content.Data.Add(item);
                    }
                }

                reader.Close();
            }

            retVal.Close();

            return(retVal);
        }
コード例 #2
0
        public static BaseHelper GetEmployeesList(Model.GetEmployeesList data)
        {
            var retVal      = new BaseHelper();
            var objJSONPage = new Output.GetEmployeesList();

            try
            {
                var entityPage = GetEmployees.GetEmployeesList(data, objJSONPage);
                if (objJSONPage.ResultCode == 1)
                {
                    retVal.SQLElapsed += entityPage.SQLElapsed;
                    retVal.SQLInfo($"sp : {entityPage.SQLDetail}, elapsed : {entityPage.SQLElapsed}");

                    retVal.IsError = (entityPage.ResultCode == 1) ? false : true;
                }
                else
                {
                    objJSONPage.ResultCode   = objJSONPage.ResultCode;
                    objJSONPage.ErrorMessage = objJSONPage.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                retVal.Exception = ex;

                if (ex is System.Data.SqlClient.SqlException sqlEx)
                {
                    retVal.SQLInfo($"sp:{sqlEx.Procedure}, line:{sqlEx.LineNumber}, detail:{data.SqlDetail}");
                    retVal.SQLException = true;

                    objJSONPage.ResultCode   = 69998;
                    objJSONPage.ErrorMessage = "SQL Exception";
                }
                else
                {
                    objJSONPage.ResultCode   = 69999;
                    objJSONPage.ErrorMessage = "Unknown Error";
                }
            }
            finally
            {
                retVal.SerializeObject <Output.GetEmployeesList>(objJSONPage);
            }

            return(retVal);
        }