void CreatePlanTB() { if (SQLiteDB.Open() == -1) { MessageBox.Show("SQLite数据库打开失败"); IsContinue = false; return; } SQLiteDB.Run("CREATE TABLE if not exists PlanTB(" + "ID INTEGER PRIMARY KEY AUTOINCREMENT," + "PlanName varchar(50)," + "PlanDateTime varchar(50)," + "Instructions varchar(255)," + "BellPath varchar(255)," + "IsRemind INTEGER," + "IsComplete integer," + "RepetitionPeriod integer," + "RepetitionDays varchar(255)" + ")"); SQLiteDB.Close(); }
/// <summary> /// 搜索今日计划 /// </summary> public static void SearchForTodayPlan(List <string[]> PlanDatas, List <p_Plan> Plans, FlowLayoutPanel flp_Plan) { Tools.PlanDataLock = true; SQLiteDB.Open(); //2019-09-20 12:28:18.000 string DoW = DateTime.Now.DayOfWeek.ToString("d") == "0" ? "7" : DateTime.Now.DayOfWeek.ToString("d"); //判断是否为周日 DateTime dt1 = DateTime.Now.Date; DateTime dt2 = dt1.AddDays(1); // 查询重复的 string sele = $"SELECT * FROM PlanTB WHERE datetime(PlanDateTime) >= datetime('{dt1.ToString("yyyy-MM-dd HH:mm")}') and datetime(PlanDateTime) <= datetime('{dt2.ToString("yyyy-MM-dd HH:mm")}') and RepetitionPeriod = -1 or RepetitionPeriod = 0 or RepetitionPeriod = 1 and RepetitionDays like '%,{DoW},%' or RepetitionPeriod = 2 and RepetitionDays like '%,{DateTime.Now.Day},%';"; //sele = "SELECT * FROM PlanTB";-- PlanDatas = SQLiteDB.Run(sele, (list) => { return(SQLiteDB.SaveData(SQLiteDB.sdr, list)); }, PlanDatas); SQLiteDB.Close(); //PlanDatas.AddRange(Tools.SearchRepetitionDays()); SQLiteDB.Close(); Tools.PlanDataLock = false; Tools.ShowPlans(PlanDatas, Plans, flp_Plan); }
/// <summary> /// 显示对应日期的计划 /// </summary> /// <param name="dt"></param> public static void ShowPlans(dynamic PlanDatas, List <p_Plan> Plans, FlowLayoutPanel flp_Plan) { flp_Plan.Controls.Clear(); Plans.Clear(); if (PlanDatas != null) { for (int i = 0; i < PlanDatas.Count; i++) { Plans.Add(new p_Plan()); //DateTime jDateTime = DateTime.Parse(PlanDatas[i][2]); //if (jDateTime.ToShortDateString() == DateTime.Now.ToShortDateString())// //{ Plans[i].l_Title.Text = PlanDatas[i][1]; Plans[i].l_DateTime.Text = PlanDatas[i][2]; Plans[i].t_Instructions.Text = PlanDatas[i][3]; Plans[i].t_Instructions.ScrollBars = ScrollBars.Both; Plans[i].BorderStyle = BorderStyle.FixedSingle; if (int.Parse(PlanDatas[i][5]) == 1) { Plans[i].IsRemind.Checked = true; } if (int.Parse(PlanDatas[i][7]) != -1) { Plans[i].check_Repeat.Checked = true; } //设置计划panel背景颜色 if (int.Parse(PlanDatas[i][6]) == 1) //完成 { Plans[i].BackColor = Color.Blue; } else if (int.Parse(PlanDatas[i][6]) == -1) //未完成 { Plans[i].BackColor = Color.Red; } else //待完成 { Plans[i].BackColor = Color.FromArgb(246, 245, 248); } flp_Plan.Controls.Add(Plans[i]); Plans[i].Click += OpenPlan; Plans[i].l_Title.Click += OpenPlan; Plans[i].l_DateTime.Click += OpenPlan; ///打开计划 void OpenPlan(Object sender, EventArgs e) { if (pf != null && !PlanForm.IsClose) { DialogResult result = MessageBox.Show("已经打开了一个计划窗口,继续此操作将会关闭已打开的窗口,是否继续?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } pf.Close(); } int index = flp_Plan.Controls.IndexOf((Control)sender); if (index == -1) { index = flp_Plan.Controls.IndexOf(((Control)sender).Parent); } pf = new PlanForm(PlanDatas[index], PlanDatas, Plans, flp_Plan); pf.Show(); } //完成 Plans[i].btn_Complete.Click += (sender, e) => { //MessageBox.Show("complete"+flp_Plan.Controls.IndexOf(((Button)sender).Parent).ToString()); int index = flp_Plan.Controls.IndexOf(((Button)sender).Parent); DateTime now = DateTime.Now.Date; if (Plans[index].BackColor != Color.Blue && now <= DateTime.Parse(PlanDatas[index][2]) || Plans[index].BackColor != Color.Blue && PlanDatas[index][7] != "-1") { Plans[index].BackColor = Color.Blue; SQLiteDB.Open(); SQLiteDB.Run($"UPDATE PlanTB SET IsComplete = 1 WHERE ID = {PlanDatas[index][0]}"); SQLiteDB.Close(); } }; //未完成 Plans[i].btn_Unfinished.Click += (sender, e) => { int index = flp_Plan.Controls.IndexOf(((Button)sender).Parent); DateTime now = DateTime.Now.Date; if (Plans[index].BackColor != Color.Red && now <= DateTime.Parse(PlanDatas[index][2]) || Plans[index].BackColor != Color.Blue && PlanDatas[index][7] != "-1") { Plans[index].BackColor = Color.Red; SQLiteDB.Open(); SQLiteDB.Run($"UPDATE PlanTB SET IsComplete = -1 WHERE ID = {PlanDatas[index][0]}"); SQLiteDB.Close(); } }; //} } } }