Example #1
0
        public ReturnMachinePart MachinePartAll()
        {
            List <MachinePart> lstMachinePart    = null;
            MachinePart        machinePart       = null;
            ReturnMachinePart  returnMachinePart = new ReturnMachinePart();

            try
            {
                using (SqlConnection sqlConnection = ConnectSQLCommon.CreateAndOpenSqlConnection())
                {
                    using (SqlCommand cmd = new SqlCommand("", sqlConnection))
                    {
                        cmd.CommandText = "sp_tMachinePart_SelectAll";
                        cmd.CommandType = CommandType.StoredProcedure;

                        using (SqlDataReader sqlDr = ConnectSQLCommon.ExecuteDataReader(cmd))
                        {
                            if (sqlDr.HasRows)
                            {
                                lstMachinePart = new List <MachinePart>();
                                while (sqlDr.Read())
                                {
                                    machinePart             = new MachinePart();
                                    machinePart.ID          = int.Parse(sqlDr["ID"].ToString());
                                    machinePart.Name        = sqlDr["Name"].ToString();
                                    machinePart.Description = sqlDr["Description"].ToString();
                                    machinePart.MachineType = int.Parse(sqlDr["MachineType"].ToString());
                                    machinePart.DateCreated = DateTime.Parse(sqlDr["DateCreated"].ToString());
                                    machinePart.TypeName    = sqlDr["TypeName"].ToString();
                                    lstMachinePart.Add(machinePart);
                                }
                                returnMachinePart.Code           = "00";
                                returnMachinePart.Message        = "Lấy dữ liệu thành công.";
                                returnMachinePart.lstMachinePart = lstMachinePart;
                            }
                            else
                            {
                                returnMachinePart.Code           = "01";
                                returnMachinePart.Message        = "Không tồn tại bản ghi nào.";
                                returnMachinePart.Total          = 0;
                                returnMachinePart.lstMachinePart = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnMachinePart.Code           = "99";
                returnMachinePart.Message        = "Lỗi xử lý dữ liệu: " + ex.ToString();
                returnMachinePart.Total          = 0;
                returnMachinePart.lstMachinePart = null;
                mylog4net.Error("", ex);
            }
            return(returnMachinePart);
        }