using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KstCMS.DAL.OleDB
{
    [Serializable]
    public class UseUnit:KstCMS.DAL.IUseUnit
    {
        public void Update(string FieldValues, int Id, params string[] FieldNames)
        {
            KstSoft.DBUtility.OleDB_Helper.DataUpdate("Regedit", Id.ToString(), FieldValues, FieldNames);
        }

        public KstCMS.Model.SiteModel.UseUnit GetModel(int Id, params string[] FieldNames)
        {
            KstCMS.Model.SiteModel.UseUnit Model = new Model.SiteModel.UseUnit();
            StringBuilder sb = new StringBuilder();
            sb.Append(KstSoft.DBUtility.OleDB_Helper.Get_SelectFieldName(0, FieldNames));
            sb.Append(" from Regedit where ID=@id");
            System.Data.OleDb.OleDbParameter[] cmdParms = new System.Data.OleDb.OleDbParameter[]{
               new System.Data.OleDb.OleDbParameter("@id",System.Data.OleDb.OleDbType.Integer)
           };
            cmdParms[0].Value = Id;
            System.Data.DataSet dsData = KstSoft.DBUtility.OleDB_Helper.Query(sb.ToString(), cmdParms);
            if (dsData.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < dsData.Tables[0].Columns.Count; i++)
                {
                    string Field = dsData.Tables[0].Columns[i].ColumnName;
                    GetField(dsData.Tables[0].Rows[0], Field, ref Model);
                }
            }
            return Model;
        }

        private  void GetField(System.Data.DataRow Row, string FieldName, ref KstCMS.Model.SiteModel.UseUnit 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;
            }
        }


    }
}
