コード例 #1
0
 public void add(THICKNESS_READING obj)
 {
     DAL.add(obj.PointID, obj.ThicknessDate, obj.Orientation, obj.MaxReading, obj.ThicknessReading, obj.CorrosionRate, obj.ValidReading, obj.Comment);
 }
        // dung file get data
        // dung file get list( data source)
        public List <THICKNESS_READING> getDataSource()
        {
            List <THICKNESS_READING> list = new List <THICKNESS_READING>();
            THICKNESS_READING        obj  = null;
            SqlConnection            conn = MSSQLDBUtils.GetDBConnection();

            conn.Open();
            String sql = "Use [rbi]" +
                         "SELECT [ThicknessID]" +
                         ",[PointID]" +
                         ",[ThicknessDate]" +
                         ",[Orientation]" +
                         ",[MaxReading]" +
                         ",[ThicknessReading]" +
                         ",[CorrosionRate]" +
                         ",[ValidReading]" +
                         ",[Comment]" +
                         "  FROM [rbi].[dbo].[THICKNESS_READING]";

            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = conn;
                cmd.CommandText = sql;
                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (reader.HasRows)
                        {
                            obj             = new THICKNESS_READING();
                            obj.ThicknessID = reader.GetInt32(0);
                            obj.PointID     = reader.GetInt32(1);
                            if (!reader.IsDBNull(2))
                            {
                                obj.ThicknessDate = reader.GetDateTime(2);
                            }
                            if (!reader.IsDBNull(3))
                            {
                                obj.Orientation = reader.GetString(3);
                            }
                            if (!reader.IsDBNull(4))
                            {
                                obj.MaxReading = reader.GetFloat(4);
                            }
                            if (!reader.IsDBNull(5))
                            {
                                obj.ThicknessReading = reader.GetFloat(5);
                            }
                            if (!reader.IsDBNull(6))
                            {
                                obj.CorrosionRate = reader.GetFloat(6);
                            }
                            obj.ValidReading = reader.GetInt32(7);
                            if (!reader.IsDBNull(7))
                            {
                                obj.Comment = reader.GetString(8);
                            }
                            list.Add(obj);
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("GET DATA SOURCE FAIL!");
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
            return(list);
        }