using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KstCmsBase.Entities;

namespace KstCmsBase.DAL
{
    public class Regedit
    {
        /// <summary>
        /// 取字段值
        /// </summary>
        /// <param name="Row"></param>
        /// <param name="FieldName"></param>
        /// <param name="WebSite"></param>
        private static void GetField(DataRow Row, string FieldName, ref UserUnit Unit)
        {
            string FieldValue = Row[FieldName].ToString();
            switch (FieldName)
            {
                case "ID":
                    Unit.ID = FieldValue;
                    break;
                case "WEBTITLE":
                    Unit.WEBTITLE = FieldValue;
                    break;
                case "SOFTNAME":
                    Unit.SOFTNAME = FieldValue;
                    break;
                case "COMNAME":
                    Unit.COMNAME = FieldValue;
                    break;
                case "TEL":
                    Unit.TEL = FieldValue;
                    break;
                case "FAX":
                    Unit.FAX = FieldValue;
                    break;
                case "ZIP":
                    Unit.ZIP = FieldValue;
                    break;
                case "ADDRESS":
                    Unit.ADDRESS = FieldValue;
                    break;
                case "URL":
                    Unit.URL = FieldValue;
                    break;
                case "IBM_CODE":
                    Unit.IBM_CODE = FieldValue;
                    break;
                case "REG_CODE":
                    Unit.REG_CODE = FieldValue;
                    break;
                case "EMAIL":
                    Unit.EMAIL = FieldValue;
                    break;
            }

        }

        public static UserUnit Get_UnitInfo(params string[] Fields)
        {
            KstCmsBase.DAL.Access db = new Access();
            string sql = db.Get_DbSQL("from Regedit", Fields);
            DataSet dsData = db.ExecuteDataSet(sql.ToString());
            UserUnit item = new UserUnit();
            if (dsData.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsData.Tables[0].Columns.Count; i++)
                {
                    string FieldName = dsData.Tables[0].Columns[i].ColumnName;
                    GetField(dsData.Tables[0].Rows[0], FieldName, ref item);
                }
            }
            dsData.Dispose();
            db.Dispose();
            return item;
        }

        public static int Update(string[] FieldsValue, int LoadID, params string[] FieldNames)
        {
            Access db = new Access();
            int r = db.DataUpdate("Regedit", "ID", LoadID, FieldsValue, FieldNames);
            db.Dispose();
            return r;
        }

    }
}
