Exemple #1
0
        void moveNode(MyNode node)
        {
            MyNode  root      = m_nodes["root"];
            MyNode  regNode   = m_nodes["register"];
            MyNode  unregNode = m_nodes["un-register"];
            MyReg   reg       = node.data as MyReg;
            MyGroup grp       = m_groups.Find(x => x.nGroup == reg.user.nGroup);
            MyNode  grpNode;

            //register
            grpNode = regNode.childs.Find(x => x.zTitle == grp.zGroup);
            if (grpNode != null)
            {
                if (!grpNode.childs.Contains(node))
                {
                    grpNode.childs.Add(node);
                }
            }
            else
            {
                grpNode = new MyNode()
                {
                    zTitle = grp.zGroup
                };
                regNode.childs.Add(grpNode);
                grpNode.childs.Add(node);
            }

            //un-register
            grpNode = unregNode.childs.Find(x => x.zTitle == grp.zGroup);
            if (grpNode != null)
            {
                if (grpNode.childs.Contains(node))
                {
                    grpNode.childs.Remove(node);
                    if (grpNode.childs.Count == 0)
                    {
                        unregNode.childs.Remove(grpNode);
                    }
                }
            }

            updateTree(root);
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        //}
        //public class lOleDbContentProvider
        //{
        //    private OleDbConnection m_cnn;
        //    OleDbDataAdapter m_dataAdapter;
        //    Dictionary<UInt64, MyUser> m_userDict;
        //public void initCnn(string m_cnnStr)
        //{
        //    //init cnn
        //    m_cnn = new OleDbConnection(m_cnnStr);
        //    m_cnn.Open();
        //    m_dataAdapter = new OleDbDataAdapter
        //    {
        //        SelectCommand = new OleDbCommand(
        //        string.Format("select * from users where titleId = ? order by ord"),
        //        m_cnn)
        //    };
        //    m_dataAdapter.SelectCommand.Parameters.Add(
        //        new OleDbParameter() { DbType = DbType.UInt64 });

        //    m_userDict = new Dictionary<ulong, MyUser>();
        //}
        //public List<MyUser> GetAllUsers()
        //{
        //    List<MyUser> userLst = new List<MyUser>();
        //    var qry = "select * from users";
        //    var cmd = new OleDbCommand(qry, m_cnn);
        //    var reader = cmd.ExecuteReader();
        //    while (reader.Read())
        //    {
        //        UInt64 uID = Convert.ToUInt64(reader["ID"]);
        //        userLst.Add(new MyUser()
        //        {
        //            ID = uID,
        //            zFb = Convert.ToString(reader["zFb"]),
        //            zUser = Convert.ToString(reader["zUser"]),
        //            nGroup = int.Parse(reader["nGroup"].ToString())
        //        });
        //    }
        //    reader.Close();
        //    return userLst;
        //}

        //public List<MyProgram> GetAllProgs()
        //{
        //    List<MyProgram> progLst = new List<MyProgram>();
        //    var qry = "select * from programs";
        //    var cmd = new OleDbCommand(qry, m_cnn);
        //    var reader = cmd.ExecuteReader();
        //    while (reader.Read())
        //    {
        //        progLst.Add(new MyProgram()
        //        {
        //            ID = Convert.ToUInt64(reader["ID"]),
        //            zName = Convert.ToString(reader["zName"]),
        //            startDate = Convert.ToDateTime(reader["startDate"])
        //        });
        //    }
        //    reader.Close();
        //    return progLst;
        //}

        //public List<MyReg> GetRegs(MyProgram prog)
        //{
        //    List<MyReg> regLst = new List<MyReg>();
        //    var qry = "SELECT * FROM program_user WHERE programID = ?";
        //    var cmd = new OleDbCommand(qry, m_cnn);
        //    cmd.Parameters.Add(cmd.CreateParameter());
        //    cmd.Parameters[0].Value = prog.ID;
        //    var reader = cmd.ExecuteReader();
        //    while (reader.Read())
        //    {
        //        regLst.Add(new MyReg()
        //        {
        //            zNote = Convert.ToString(reader["zNote"]),
        //            nStatus = int.Parse(reader["nStatus"].ToString()),
        //            zStatus = Convert.ToString(reader["zStatus"]),
        //            userID = Convert.ToUInt64(reader["userID"]),
        //            programID = Convert.ToUInt64(reader["programID"])
        //        });
        //    }
        //    reader.Close();
        //    return regLst;
        //}
        //public List<MyGroup> GetAllGroups()
        //{
        //    List<MyGroup> grpLst = new List<MyGroup>();
        //    var qry = "SELECT * FROM groups";
        //    var cmd = new OleDbCommand(qry, m_cnn);
        //    var reader = cmd.ExecuteReader();
        //    while (reader.Read())
        //    {
        //        grpLst.Add(new MyGroup()
        //        {
        //            ID = Convert.ToUInt64(reader["ID"]),
        //            nGroup = int.Parse(reader["nGroup"].ToString()),
        //            zGroup = Convert.ToString(reader["zGroup"]),
        //        });
        //    }
        //    reader.Close();
        //    return grpLst;
        //}

        public int AddUpdateReg(MyReg reg)
        {
            {
                var cmd = new OleDbCommand("SELECT ID FROM program_user WHERE userID = ? AND programID = ?", m_cnn);
                cmd.Parameters.Add("", OleDbType.Numeric).Value = reg.userID;
                cmd.Parameters.Add("", OleDbType.Numeric).Value = reg.programID;
                var id = cmd.ExecuteScalar();
                if (id != null)
                {
                    reg.ID = Convert.ToUInt64(id);
                }
            }

            if (reg.ID != 0)
            {
                var cmd = new OleDbCommand("UPDATE program_user SET nStatus = ?, zNote = ? WHERE ID = ?", m_cnn);
                cmd.Parameters.Add("", OleDbType.Numeric).Value = reg.nStatus;
                cmd.Parameters.Add("", OleDbType.Char).Value    = reg.zNote;
                cmd.Parameters.Add("", OleDbType.Numeric).Value = reg.ID;
                var n = cmd.ExecuteNonQuery();
                return(n);
            }
            else
            {
                var cmd = new OleDbCommand("INSERT INTO program_user (userID, programID, nStatus, zNote) VALUES (?, ?, ?, ?)", m_cnn);
                cmd.Parameters.Add("", OleDbType.Numeric).Value   = reg.userID;
                cmd.Parameters.Add("", OleDbType.Numeric).Value   = reg.programID;
                cmd.Parameters.Add("", OleDbType.Numeric).Value   = reg.nStatus;
                cmd.Parameters.Add("", OleDbType.Char, 255).Value = reg.zNote;
                var n = cmd.ExecuteNonQuery();

                cmd.CommandText = "Select @@Identity";
                var id = cmd.ExecuteScalar();
                reg.ID = Convert.ToUInt64(id);
                return(n);
            }
        }