public bool LogsSaveAdd(MyProgram prog) { //get new id UInt64 lastId = 0; try { var cmd = new OleDbCommand("SELECT max(ID) from logs", m_cnn); lastId = Convert.ToUInt64(cmd.ExecuteScalar()); } catch { //empty table } //insert var cmd2 = new OleDbCommand("INSERT INTO logs (ID,modifyDate,zLog) VALUES (@ID,@modifyDate,@zLog)", m_cnn); var action = new MyAction() { actiontype = "add", objType = prog.ToString(), jsonText = JsonConvert.SerializeObject(prog) }; var txt = JsonConvert.SerializeObject(action); cmd2.Parameters.Add(new OleDbParameter("@ID", OleDbType.Numeric)); cmd2.Parameters.Add(new OleDbParameter("@modifyDate", OleDbType.Date)); cmd2.Parameters.Add(new OleDbParameter("@zLog", OleDbType.LongVarWChar)); cmd2.Parameters["@ID"].Value = lastId + 1; cmd2.Parameters["@modifyDate"].Value = DateTime.Now;; cmd2.Parameters["@zLog"].Value = txt; var n = cmd2.ExecuteNonQuery(); return(n == 1); }
private MyTree.MyTitle Prog2Title(MyProgram prog) { MyTree.MyTitle title = new MyTree.MyTitle(); title.title = prog.zName; title.path = string.Format("{0}/{1}", prog.zPath, prog.zName); title.ID = prog.ID; return(title); }
private void OnCrtNewProg(object sender, EventArgs e) { //show input dlg var inputDlg = new inputProg(); inputDlg.path = ""; if (programTV.SelectedNode != null) { inputDlg.path = programTV.SelectedNode.FullPath.Replace("\\", "/"); } inputDlg.name = string.Format("new prog {0}-{1}", DateTime.Now.Day, DateTime.Now.Month); inputDlg.date = DateTime.Now; var ret = inputDlg.ShowDialog(); if (ret == DialogResult.OK) { //check duplicate var newProg = new MyProgram() { zPath = inputDlg.path, zName = inputDlg.name, startDate = inputDlg.date }; if (!m_progTreeMng.PathExist(newProg.zPath + "/" + newProg.zName)) { //add new prog var bOK = m_cp.AddProg(newProg); if (bOK) { //add to log m_cp.LogsSaveAdd(newProg); //update gui var title = Prog2Title(newProg); m_programs.Add(newProg); m_progTreeMng.Add(title); //update combo progCmb.Items.Insert(0, newProg.zName); progCmb.SelectedIndex = 0; } } } }
public bool AddProg(MyProgram myProgram) { var pathID = AddPath(myProgram.zPath); var cmd = new OleDbCommand("INSERT INTO programs (zName, startDate, pathID) VALUES (@zName,@startDate,@pathID)", m_cnn); cmd.Parameters.Add(new OleDbParameter("@zName", OleDbType.Char)); cmd.Parameters.Add(new OleDbParameter("@startDate", OleDbType.Date)); cmd.Parameters.Add(new OleDbParameter("@pathID", OleDbType.Numeric)); cmd.Parameters["@zName"].Value = myProgram.zName; cmd.Parameters["@startDate"].Value = myProgram.startDate; cmd.Parameters["@pathID"].Value = pathID; var n = cmd.ExecuteNonQuery(); //update id var newID = Convert.ToUInt64(new OleDbCommand("Select @@Identity", m_cnn).ExecuteScalar().ToString()); myProgram.ID = newID; return(n == 1); }
private void AddBtn_Click(object sender, EventArgs e) { int nOpt; string zOpt; var txt = optTxt.Text; bool v = ParseOpt(txt, out zOpt, out nOpt); if (!v) { return; } var zUserFb = userCmb.Text; MyUser user = m_users.Find(x => x.zUserFb == zUserFb); var zProg = progCmb.Text; MyProgram prog = m_programs.Find(x => x.zName == zProg); MyReg myReg = new MyReg(); myReg.userID = user.ID; myReg.programID = prog.ID; myReg.nStatus = nOpt; myReg.zNote = zOpt; int ret = m_cp.AddUpdateReg(myReg); //add to ricktext richTextBox1.SelectedText = user.zUserFb + string.Format("({0}-{1})\n", nOpt, zOpt); richTextBox1.ScrollToCaret(); MyTree.MyTitle title = new MyTree.MyTitle(); MyGroup grp = m_groups.Find(x => x.nGroup == user.nGroup); title.title = user.zUserFb; title.content = string.Format("{0} ({1})", nOpt, zOpt); title.path = string.Format("register/{0}/{1}", grp.zGroup, user.zUserFb); var nRet = m_treeMng.Add(title); if (nRet == 1) { title.path = string.Format("un-register/{0}/{1}", grp.zGroup, user.zUserFb); m_treeMng.Remove(title); } }
public List <MyReg> GetRegs(MyProgram prog) { return(GetRegs(prog.ID)); }