using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;

[DataObject(true)]
public class TEC_WorkStatusNameData : SqlData {
    public TEC_WorkStatusNameData() {
        DataConnection = ConfigurationManager.ConnectionStrings["ConnString_SEST"].ConnectionString;
        TableName = "TEC_WorkStatusName";
        PrimaryKeyColumnNames = new string[] { "StatusName" };
    }


    [DataObjectMethod(DataObjectMethodType.Select, true)]
    public DataTable Select() {
        DataTable dt = new DataTable(TableName);

        using (SqlConnection cn = new SqlConnection(DataConnection))
        using (SqlDataAdapter da = new SqlDataAdapter(
            "SELECT [StatusName] " +
            " ,[CName] " +
            " ,[JName] " +
            " FROM " + TableName + " ORDER BY " + PrimaryKeyColumnNames[0], cn)) {
            da.Fill(dt);
            return dt;
            //string[] ar = new string[dt.Rows.Count];
            //int i = 0;
            //foreach (DataRow dr in dt.Rows) {
            //    ar[i] = dr.ItemArray[0].ToString();
            //    i++;
            //}
            //return ar;
        }
    }
    public string[] SelectAddEmptyItem() {
        DataTable dt = new DataTable(TableName);

        using (SqlConnection cn = new SqlConnection(DataConnection))
        using (SqlDataAdapter da = new SqlDataAdapter(
            "SELECT [StatusName] " +
            " FROM " + TableName + " ORDER BY " + PrimaryKeyColumnNames[0], cn)) {
            da.Fill(dt);
            string[] ar = new string[dt.Rows.Count + 1];
            ar[0] = "";
            int i = 1;
            foreach (DataRow dr in dt.Rows) {
                ar[i] = dr.ItemArray[0].ToString();
                i++;
            }
            return ar;
        }
    }
    public string[] SelectCNameAddEmptyItem() {
        DataTable dt = new DataTable(TableName);

        using (SqlConnection cn = new SqlConnection(DataConnection))
        using (SqlDataAdapter da = new SqlDataAdapter(
            "SELECT [CName] " +
            " FROM " + TableName + " ORDER BY " + PrimaryKeyColumnNames[0], cn)) {
            da.Fill(dt);
            string[] ar = new string[dt.Rows.Count + 1];
            ar[0] = "";
            int i = 1;
            foreach (DataRow dr in dt.Rows) {
                ar[i] = dr.ItemArray[0].ToString();
                i++;
            }
            return ar;
        }
    }
}