using ryCommon;
using ryCommonDb;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using static ryCommonDb.DataProvider;

namespace Itrycn_Project2
{
    /// <summary>
    /// 配置类(本系统基于乘黄V1架构)
    /// </summary>
    public class Itrycn_Info
    {
        /// <summary>
        /// 是否能关闭窗体。
        /// </summary>
        public static bool isCanCloseForm = true;
        /// <summary>
        /// 在线升级配置文件的url
        /// </summary>
        public static string Update_Url = "http://www.itrycn.com/update/ryWebMon4.xml";
        /// <summary>
        /// 软件标题
        /// </summary>
        public static string Soft_Title = "睿元管理系统";
        /// <summary>
        /// 软件ID
        /// </summary>
        public static string Soft_Id = "Money_Op";
        /// <summary>
        /// 开机启动的参数
        /// </summary>
        public static string Soft_Pram = "q";
        /// <summary>
        /// 官网地址
        /// </summary>
        public static string Soft_Url = "http://www.itrycn.com";
        /// <summary>
        /// 用户文件夹,该相对路径设置,将在程序启动后转换
        /// </summary>
        public static string UserDataFolder = "<app>\\UserDb";
        /// <summary>
        /// 左边分类内容新增
        /// </summary>
        /// <param name="frm"></param>
        public static void OnLeftTreeAdd(Itrycn.Frmmain frm)
        {
            frm.AddToTreeView(frm.treeView1.Nodes[0], typeof(DbOp.FrmView), "测试", "item.png");
            Itrycn_Info.LoadSetting();
        }
        public static void LoadSetting()
        {
            //ryCommon.Storage Stor = new Storage();
            //Stor.SelectNodeBySet();
            //LowCountTip = Stor.GetAttrValue("LowCountTip", true);
            //low_count = Stor.GetAttrValue("LowCount", 10);
        }
        /// <summary>
        /// 单击分类时激发
        /// </summary>
        /// <param name="frm"></param>
        /// <param name="e"></param>
        public static void OnTreeClick(Itrycn.Frmmain frm, TreeViewEventArgs e)
        {
            Type id = (Type)e.Node.Tag;
            frm.ShowForm(id);
        }
    }
    public class Itrycn_Db
    {
        public static string SQLConnStr = "<app>\\UserDb\\myDb.dat|";
        public static ryCommonDb.DataProvider.DataProviderType dataType = ryCommonDb.DataProvider.DataProviderType.SQLiteDataProvider;
        public static IDbInterface CreateDataProvider()
        {
            return CreateDataProvider(dataType);
        }

        public static IDbInterface CreateDataProvider(DataProviderType dataProviderType)
        {
            switch (dataProviderType)
            {
                //case DataProviderType.OdbcDataProvider:
                //    return new OdbcDataProvider();
                //case DataProviderType.OleDbDataProvider:
                //    return new OleDbDataProvider();
                //case DataProviderType.OracleDataProvider:
                //    return new OracleDataProvider();
                case DataProviderType.SQLiteDataProvider:
                    return new SQLiteDataProvider();
                default:
                    return null;
            }
        }
        private static void CreateTable(ryCommonDb.DataProvider.DataProviderType dataType, string ConnStr)
        {
            DataProvider mydb = new DataProvider();
            IDbInterface db = CreateDataProvider(dataType);
            if (db.ConnDb(ConnStr) == 1)
            {
                #region 表1
                RyQuickSQL mySQL = new RyQuickSQL("表1");
                mySQL.AddField("", "");
                mySQL.AddField("addTime", DateTime.Now);
                mySQL.AddField("editTime", DateTime.Now);
                db.CreateDb(mySQL); 
                #endregion
                //
                #region 表2
                mySQL.Clear();
                mySQL.TableName = "表2";
                mySQL.AddField("", "");
                db.CreateDb(mySQL); 
                #endregion
            }
            db.Free();
        }
        public static void CreateTable()
        {
            CreateTable(dataType, SQLConnStr);
        }
    }
}
