using ryCommon;
using ryCommonDb;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TimeClock.DbOp
{
    public partial class FrmToDo_Log : Form
    {
        public FrmToDo_Log()
        {
            InitializeComponent();
        }
        public void LoadDb(int id)
        {
            table_todo.TableModel.Rows.Clear();
            DataProvider mydb = new DataProvider();
            IDbInterface db = TimeClock.Itrycn_Db.CreateDataProvider(TimeClock.Itrycn_Db.dataType);
            if (db.ConnDb(TimeClock.Itrycn_Db.SQLConnStr) == 1)
            {
                RyQuickSQL mySQL = new RyQuickSQL("ToDo_logs");
                mySQL.AddParameter("todo_id", id);
                DataSet ds = db.ReadData("select * from ToDo_logs where todo_id=@todo_id order by addTime desc", mySQL);
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow row = ds.Tables[0].Rows[i];
                    XPTable.Models.Row itemList = new XPTable.Models.Row();
                    //需要修改此处
                    itemList.Cells.Add(new XPTable.Models.Cell(row["addTime"].ToDateTime().ToString("yyyy-MM-dd dddd HH:mm:ss")));//示例
                    itemList.Cells.Add(new XPTable.Models.Cell(row["log_text"].ToString()));//示例
                    table_todo.TableModel.Rows.Add(itemList);
                }
                DataSet ds_todo = db.ReadData("select * from ToDo where id=" + id);
                if (mydb.HaveData(ds_todo))
                {
                    var row = mydb.GetData(ds_todo);
                    Text = "待办操作记录[" + row["name"].ToString() + "]";
                    XPTable.Models.Row itemList = new XPTable.Models.Row();
                    //需要修改此处
                    itemList.Cells.Add(new XPTable.Models.Cell(row["addTime"].ToDateTime().ToString("yyyy-MM-dd dddd HH:mm:ss")));//示例
                    itemList.Cells.Add(new XPTable.Models.Cell("创建该待办"));//示例
                    table_todo.TableModel.Rows.Add(itemList);
                }
                ColAddTime.Text = "时间("+table_todo.TableModel.Rows.Count+")";
                db.Free();
            }
        }
        private void FrmToDo_Log_Load(object sender, EventArgs e)
        {

        }

        private void table_todo_Click(object sender, EventArgs e)
        {
            if (table_todo.SelectedItems.Length == 0) {richTextBox1.Text=""; return; }
            richTextBox1.Text = table_todo.SelectedItems[0].Cells[ColLogs.Index].Text;
        }
    }
}
