// 当前念佛窗口从打开到关闭,储存的一个过程的record,每次按enter键就会保存到当前record中 public MainForm() { InitializeComponent(); //Fullscreen(); PauseScreen(); dc.Connect(); var record = dc.GetLatestRecord(); if (record != null) { //MessageBox.Show(record.startDateTime.ToLongDateString()+" "+record.startDateTime.ToLongTimeString()); CloudUtils.loadRecords(record.startDateTime, (code, msg) => { loadHistoryRecords(); }); } else { CloudUtils.loadRecords(new DateTime(1970, 1, 1), (code, msg) => { loadHistoryRecords(); }); } }
private void button1_Click(object sender, EventArgs e) { var time = dateTimePicker1.Value; time = time.AddHours(-(double)(time.Hour)); time = time.AddHours((double)numericUpDown2.Value); time = time.AddMinutes(-time.Minute); time = time.AddSeconds(-time.Second); int count = (int)numericUpDown1.Value; if (count > 0) { /** * 生成并添加buddha **/ //var dc = new DataContext(); //dc.Connect(); var newBuddhaList = new List <Record>(); var latestBuddha = MainForm.dc.GetLatestRecord(); var avgDuration = 600000; for (int i = count; i > 0; i--) { var startTime = DateTime.Now; startTime = startTime.AddMilliseconds(-1 * avgDuration * i); newBuddhaList.Add(new Record(startTime, avgDuration, 1, "计时计数念佛", 11)); } MainForm.dc.AddRecords(newBuddhaList); /** * 整合数据 */ var uploadList = Utils.IntegrateBuddhaList(latestBuddha.startDateTime); /** * 上传数据 */ CloudUtils.uploadRecords(uploadList, (code, result) => { if (code == 0) { this.DialogResult = DialogResult.OK; this.Close(); } MessageBox.Show(result); }); //dc.Close(); } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { mediaPlayer.Stop(); if (isPlaying) { currentDuration += DateTime.Now.Subtract(currentStartTime).TotalMilliseconds; timer1.Stop(); } var cc = (int)(currentDuration / (60 * 1000 * 10)); if (cc > 0) { var record = new Record(currentStartTime, (long)currentDuration, cc, "计时计数念佛", 11); dc.AddRecord(record); CloudUtils.uploadRecord(record, (code, msg) => { //this.Invoke(new FormControlInvoker(() => { MessageBox.Show(msg); //})); }); } dc.Close(); }
public static void buildBuddhaListAndSave(int count, DateTime stoptime, long avgDuration, BuildBuddhaListCallback callback) { try { if (count < 1) { callback(-1, "count<1,不会计入数据库"); return; } var buddhaList = new List <Record>(); DateTime tmpTime = new DateTime(1970, 1, 1); Record buddha = null; for (int index = count; index > 1; index--) { if (tmpTime.Year == 1970 || buddha == null) { tmpTime = stoptime; tmpTime = tmpTime.AddMilliseconds(-1 * avgDuration * index); buddha = new Record(tmpTime, avgDuration, 1, "计时计数念佛", 11); } else { var startTime = stoptime; startTime = startTime.AddMilliseconds(-1 * avgDuration * index); if (startTime.DayOfYear == tmpTime.DayOfYear && startTime.Hour == tmpTime.Hour) { buddha.duration += avgDuration; buddha.count += 1; } else { buddhaList.Add(buddha); buddha = new Record(startTime, avgDuration, 1, "计时计数念佛", 11); tmpTime = startTime; } } } if (buddha != null) { buddhaList.Add(buddha); } CloudUtils.uploadRecords(buddhaList, (code, result) => { switch (code) { case 0: //var dc = new DataContext(); MainForm.dc.AddRecords(buddhaList); callback(code, result); break; default: callback(code, result); break; } }); } catch (Exception ex) { callback(-1, ex.Message); } }
private void Form1_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: if (isPlaying) { return; } listDate = listDate.AddDays(-1); loadHistoryRecords(); break; case Keys.Right: if (isPlaying) { return; } if (listDate.DayOfYear != DateTime.Today.DayOfYear) { listDate = listDate.AddDays(1); loadHistoryRecords(); } break; case Keys.Tab: flowLayoutPanel2.Visible = !flowLayoutPanel2.Visible; break; case Keys.Up: if (fileIndex < 3) { mediaPlayer.Stop(); fileIndex++; switch (fileIndex) { case 1: mediaPlayer = new MediaPlayer(Properties.Resources.buddha1); labelIndex.Text = "低"; break; case 2: mediaPlayer = new MediaPlayer(Properties.Resources.buddha2); labelIndex.Text = "中"; break; case 3: mediaPlayer = new MediaPlayer(Properties.Resources.buddha3); labelIndex.Text = "高"; break; } if (isPlaying) { mediaPlayer.play(); } dc.EditSetting("fileIndex", fileIndex + ""); } break; case Keys.Down: if (fileIndex > 1) { mediaPlayer.Stop(); fileIndex--; switch (fileIndex) { case 1: mediaPlayer = new MediaPlayer(Properties.Resources.buddha1); labelIndex.Text = "低"; break; case 2: mediaPlayer = new MediaPlayer(Properties.Resources.buddha2); labelIndex.Text = "中"; break; case 3: mediaPlayer = new MediaPlayer(Properties.Resources.buddha3); labelIndex.Text = "高"; break; } if (isPlaying) { mediaPlayer.play(); } dc.EditSetting("fileIndex", fileIndex + ""); } break; case Keys.Escape: if (isPlaying) { this.WindowState = FormWindowState.Minimized; } else { this.Close(); } break; case Keys.Delete: currentStartTime = DateTime.Now; currentDuration = 0; if (!isPlaying) { this.labelTime.Text = "00 : 00 : 00"; this.labelCount.Text = "0"; } break; case Keys.Space: if (isPlaying == false) { /** * 开始念佛 / 重新开始念佛 **/ currentStartTime = DateTime.Now; timer1.Start(); mediaPlayer.play(); isPlaying = true; Fullscreen(); } else { /** * 暂停念佛 **/ currentDuration += (long)DateTime.Now.Subtract(currentStartTime).TotalMilliseconds; timer1.Stop(); mediaPlayer.Pause(); isPlaying = false; PauseScreen(); } break; case Keys.Enter: var duration = isPlaying ? (DateTime.Now.Subtract(currentStartTime).TotalMilliseconds + currentDuration) : (0 + currentDuration); var count = (int)(duration / (600000)); var avgDuration = duration / count; if (currentStartTime.Year != DateTime.Now.Year || count < 1) { return; } /** * 生成并添加buddha **/ var newBuddhaList = new List <Record>(); var latestBuddha = dc.GetLatestRecord(); for (int i = count; i > 0; i--) { var startTime = DateTime.Now; startTime = startTime.AddMilliseconds(-1 * avgDuration * i); newBuddhaList.Add(new Record(startTime, (long)avgDuration, 1, "计时计数念佛", 11)); } dc.AddRecords(newBuddhaList); /** * 整合数据 */ var uploadList = Utils.IntegrateBuddhaList(latestBuddha.startDateTime); /** * 上传数据 */ CloudUtils.uploadRecords(uploadList, (code, result) => { if (code == 0) { this.labelTime.ForeColor = Color.White; this.labelCount.ForeColor = Color.White; this.labelTime.Text = "00 : 00 : 00"; this.labelCount.Text = "0"; currentStartTime = DateTime.Now; currentDuration = 0; loadHistoryRecords(); } MessageBox.Show(result); }); //Utils.buildBuddhaListAndSave(count, DateTime.Now, (long)avgDuration, (code, result) => // { // if (code == 0) // { // this.labelTime.ForeColor = Color.White; // this.labelCount.ForeColor = Color.White; // this.labelTime.Text = "00 : 00 : 00"; // this.labelCount.Text = "0"; // currentStartTime = DateTime.Now; // currentDuration = 0; // loadHistoryRecords(); // } // MessageBox.Show(result); // }); //var record = new Record(currentStartTime, (long)dd, cc, "计时计数念佛", 11); //dc.AddRecord(record); //CloudUtils.uploadRecord(record, (code, msg) => //{ // //this.Invoke(new FormControlInvoker(() => { // MessageBox.Show(msg); // //})); //}); break; case Keys.Q: MessageBox.Show(loadMonthRecords()); break; } }