예제 #1
0
        private void SaveCheckin(string kidid,string fldRoomID = "")
        {
            js = new Connector(AccessRegistryTool.ReadValue("DBServer"),"Kids_Checkin","kidschurch","1nt3gr1ty@ENLI");

            if (kidid == "")
            {
                return;
            }

            DataGridViewImageColumn img = new DataGridViewImageColumn();
            int age = 0;
            int group = 0;
            bool passed = false;

            string pathfile = js.GetPath() + "/Kids/" + js.Lookup("fldPicture", "tblKids", "fldID='" + kidid + "'");

            string roomid;
            string room = "";

            string firstname = js.Lookup("fldNickName", "tblKids", "fldID='" + kidid + "'");
            string Lastname = js.Lookup("fldLastName", "tblKids", "fldID='" + kidid + "'");

            age = js.GetAge(Convert.ToDateTime(js.Lookup("fldBirthday", "tblKids", "fldID='" + kidid + "'")));

            if (fldRoomID == "")
            {
                roomid = js.Lookup("fldID", "tblRoom", "fldRoom='" + txtRoom.Text + "'");
                room = js.Lookup("fldRoom", "tblRoom", "fldID=" + roomid);
            }
            else
            {
                roomid = fldRoomID;
                room = js.Lookup("fldRoom", "tblRoom", "fldID=" + roomid);
                passed = true;
            }

            if (age <= Convert.ToInt32(txtAge1.Text) && age >= Convert.ToInt32(txtAge2.Text))
            {
                int rooms = 0;
                string id = js.Lookup("fldID", "tblCustomizedEvent", "fldEventCode='" + this.Text + "'");

                rooms = int.Parse(js.Lookup("Count(*)","tblCustomizedEventRooms","fldCEventID='" + id + "'"));

                if(rooms>1)
                {
                    string qry = "SELECT er.fldRoomID,r.fldRoom FROM tblCustomizedEventRooms er " +
                              "  LEFT OUTER JOIN tblRoom r on r.fldID=er.fldRoomID" +
                               " WHERE er.fldMaxCapacity>(SELECT Count(*) FROM tblAttendance WHERE fldRoomID=er.fldRoomID AND fldLoginDateTime BETWEEN '" + DateTime.Now.ToShortDateString() + " 00:00:00' AND '" + DateTime.Now.ToShortDateString() + " 23:59:59' AND fldEventID='" + fldEventID + "')" +
                               " AND fldCEventID='" + id + "' AND er.fldAgeFrom<=" + age + " AND er.fldAgeTo>=" + age;

                    js.RiD.Read();

                    //string roomid = "";

                    if (js.RiD.HasRows)
                    {
                        room = "" + js.RiD["fldRoom"].ToString();
                        roomid = js.RiD["fldRoomID"].ToString();
                        passed = true;
                    }
                    else
                    {
                            roomid = js.Lookup("fldID", "tblCustomizedEventRooms", "fldAgeFrom<=" + age + " AND fldAgeTo>=" + age + " AND fldCEventID='" + id + "'");
                            room = js.Lookup("fldRoom", "tblRoom", "fldID='" +roomid + "'");
                    }

                }
                else
                {
                    lblNotification.ForeColor = System.Drawing.Color.Red;
                    lblNotification.Text = firstname + " " + Lastname + " does not belong to this Group";
                    pbOverride.Tag = null;
                    pbOverride.Visible = false;
                    return;
                }

            }
            else if(age > Convert.ToInt32(txtAge2.Text))
            {
                int rooms = 0;
                string id = js.Lookup("fldID", "tblCustomizedEvent", "fldEventCode='" + this.Text + "'");

                rooms = int.Parse(js.Lookup("Count(*)", "tblCustomizedEventRooms", "fldCEventID='" + id + "'"));

                if (rooms>1)
                {

                    string qry = "SELECT er.fldRoomID,r.fldRoom FROM tblCustomizedEventRooms er " +
                              "  LEFT OUTER JOIN tblRoom r on r.fldID=er.fldRoomID" +
                               " WHERE er.fldMaxCapacity>(SELECT Count(*) FROM tblAttendance WHERE fldRoomID=er.fldRoomID AND fldLoginDateTime BETWEEN '" + DateTime.Now.ToShortDateString() + " 00:00:00' AND '" + DateTime.Now.ToShortDateString() + " 23:59:59' AND fldEventID='" + fldEventID + "')" +
                               " AND fldCEventID='" + id + "' AND er.fldAgeFrom<=" + age + " AND er.fldAgeTo>=" + age;

                    js.ExecuteQuery(qry);

                    js.RiD.Read();

                    //string roomid = "";

                    if (js.RiD.HasRows)
                    {
                        room = "" + js.RiD["fldRoom"].ToString();
                        roomid = js.RiD["fldRoomID"].ToString();
                        passed = true;
                    }
                    else
                    {
                        roomid = js.Lookup("fldID", "tblCustomizedEventRooms", "fldAgeFrom<=" + age + " AND fldAgeTo>=" + age + " AND fldCEventID='" + id + "'");
                        room = js.Lookup("fldRoom", "tblRoom", "fldID='" + roomid + "'");

                        if(room=="")
                        {
                            lblNotification.Text = firstname + " " + Lastname + " does not belong to this group";
                            pbOverride.Tag = kidid;
                            pbOverride.Visible = true;
                            return;
                        }
                        else if (room != txtRoom.Text)
                        {
                            passed = true;
                        }
                    }

                    //js.showInformation("The child logged in to room " + room);

                }
                else
                {
                    lblNotification.Text = firstname + " " + Lastname + " does not belong to this group";
                    pbOverride.Tag = kidid;
                    pbOverride.Visible = true;
                    return;
                }

            }
            else
            {
                pbOverride.Visible = false;

                //if(lblCount.Text==lblTotal.Text)
                //{
                int rooms = 0;
                string id = js.Lookup("fldID", "tblCustomizedEvent", "fldEventCode='" + this.Text + "'");

                rooms = int.Parse(js.Lookup("Count(*)", "tblCustomizedEventRooms", "fldCEventID='" + id + "'"));

                    if (rooms>=1)
                    {
                        string qry = "SELECT er.fldRoomID,r.fldRoom FROM tblCustomizedEventRooms er " +
                               "  LEFT OUTER JOIN tblRoom r on r.fldID=er.fldRoomID" +
                                " WHERE er.fldMaxCapacity>(SELECT Count(*) FROM tblAttendance WHERE fldRoomID=er.fldRoomID AND fldLoginDateTime BETWEEN '" + DateTime.Now.ToShortDateString() + " 00:00:00' AND '" + DateTime.Now.ToShortDateString() + " 23:59:59' AND fldEventID='" + fldEventID + "')" +
                                " AND fldCEventID='" + id + "' AND er.fldAgeFrom<=" + age + " AND er.fldAgeTo>=" + age;

                        js.ExecuteQuery(qry);

                        js.RiD.Read();

                        //string roomid = "";

                        if (js.RiD.HasRows)
                        {
                            room = "" + js.RiD["fldRoom"].ToString();
                            roomid = js.RiD["fldRoomID"].ToString();
                            passed = true;
                        }
                        else
                        {
                            roomid = js.Lookup("fldID", "tblCustomizedEventRooms", "fldAgeFrom<=" + age + " AND fldAgeTo>=" + age + " AND fldCEventID='" + id + "'");
                            room = js.Lookup("fldRoom", "tblRoom", "fldID='" + roomid + "'");

                            if (room == "")
                            {
                                lblNotification.Text = firstname + " " + Lastname + " does not belong to this group";
                                pbOverride.Tag = kidid;
                                pbOverride.Visible = false;
                                return;
                            }
                            else if (room != txtRoom.Text)
                            {
                                passed = true;
                            }

                        }

                        //js.showInformation("The child logged in to room " + room);

                    }
                //}
            }

            if (System.IO.File.Exists(pathfile))
            {
                img.Image = Image.FromFile(pathfile);

                img.Image = (Image)(new Bitmap(img.Image, new Size(150, 150)));
            }
            else
            {
                img.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                img.Image = (Image)(new Bitmap(img.Image, new Size(150, 150)));
            }

            pbImageKid.Image = img.Image;

            txtName.Text = firstname + " " + Lastname;

            txtBirthday.Text = Convert.ToDateTime(js.Lookup("fldBirthday", "tblKids", "fldID='" + kidid + "'")).ToShortDateString();

            DateTime sdate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd"));
            DateTime edate = sdate.AddDays(6);
            DateTime bd = Convert.ToDateTime(Convert.ToDateTime(txtBirthday.Text).ToString("MM/dd"));

            if (bd >= sdate && bd <= edate)
            {
                pbBirthday.Visible = true;
                pbPopper.Visible = true;

            }
            else
            {
                pbBirthday.Visible = false;
                pbPopper.Visible = false;
            }

            txtAllergies.Text = js.Lookup("fldAllergies", "tblKids", "fldID='" + kidid + "'");

            txtAge.Text = js.GetAge(Convert.ToDateTime(txtBirthday.Text)).ToString();

            txtBarcode.Text = js.Lookup("fldStudentID", "tblKids", "fldID='" + kidid + "'");

            txtNFC.Text = js.Lookup("fldNFCCode", "tblKidsNFC", "fldKidID='" + kidid + "'");

            if (Convert.ToDecimal(age) < 2)
            {
                group = 1;
            }

            else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
            {
                group = 2;
            }

            else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
            {
                group =3;
            }

            else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
            {
                group = 4;
            }

            else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
            {
                group = 5;
            }

            else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
            {
                group =6;
            }

            else
            {
                group = 0;
            }

            string q = "INSERT INTO tblAttendance(fldRoomID,fldChurch,fldLoginDateTime,fldKidsID,fldEventID,fldGroupID,fldAge) VALUES('" + roomid + "','" + 1 + "','" + DateTime.Now.ToString() + "','" + txtBarcode.Text + "','" + fldEventID + "','" + group + "','" + age + "')";

            //string q = "INSERT INTO tblAttendance(fldRoomID,fldChurch,fldLoginDateTime,fldKidsID,fldEventID) VALUES('" + roomid + "','" + 1 + "','" + DateTime.Now.ToString() + "','" + kidid + "','" + fldEventID + "')";

            js.ExecuteNonQuery(q);

            dgvAttendance.Rows.Add(kidid, img.Image);

            pbLoading.Visible = true;

            if (Properties.Settings.Default.PairedDevices != "")
            {
                string[] devices = Properties.Settings.Default.PairedDevices.Split(char.Parse(","));

                if (devices[0] == "")
                {
                    string device = Properties.Settings.Default.PairedDevices;

                    string[] properties = device.Split(char.Parse("|"));

                    Connector con = new Connector(properties[1], "Kids_Checkin", "kidschurch", "1nt3gr1ty@ENLI");

                    try
                    {
                        Application.DoEvents();
                        con.ExecuteNonQuery(q);
                        //con.CloseConnection();
                    }
                    catch(Exception ex)
                    {
                        errBallontoolTip("Kids Checkin System", ex.Message);
                        //con.CloseConnection();
                    }

                    txtRoom.Text = room;
                    this.Tag = room;
                    frmLogin_Load(null, null);
                    lblNotification.ForeColor = System.Drawing.Color.Green;
                    lblNotification.Text = "Successfully Logged In";
                    pbLoading.Visible = false;
                    return;
                }

                for (int i = 0; i <= (devices.Length - 1); i++)
                {
                    string device = devices[i];

                    string[] properties = device.Split(char.Parse("|"));

                    try
                    {

                        Application.DoEvents();
                        Connector con = new Connector(properties[1], "Kids_Checkin", "kidschurch", "1nt3gr1ty@ENLI");
                        con.ExecuteNonQuery(q);
                        //con.CloseConnection();
                    }
                    catch(Exception ex)
                    {
                        errBallontoolTip("Kids Checkin System", ex.Message);
                        //con.CloseConnection();
                    }

                }

            }

            pbLoading.Visible = false;

            txtRoom.Text = room;
            this.Tag = room;
            frmLogin_Load(null, null);
            lblNotification.ForeColor = System.Drawing.Color.Green;
            lblNotification.Text = "Successfully Logged In";
        }
예제 #2
0
        private void pbOverride_Click(object sender, EventArgs e)
        {
            js = new Connector(AccessRegistryTool.ReadValue("DBServer"), "Kids_Checkin", "kidschurch", "1nt3gr1ty@ENLI");
            tmrReader.Enabled = false;
            DataGridViewImageColumn img = new DataGridViewImageColumn();
            int age = 0;
            int group = 0;

            string pathfile = js.GetPath() + "/Kids/" + js.Lookup("fldPicture", "tblKids", "fldID='" + pbOverride.Tag + "'");

            string roomid = js.Lookup("fldID", "tblRoom", "fldRoom='" + txtRoom.Text + "'");

            string firstname = js.Lookup("fldNickName", "tblKids", "fldID='" + pbOverride.Tag + "'");
            string Lastname = js.Lookup("fldLastName", "tblKids", "fldID='" + pbOverride.Tag + "'");
            bool correct = false;
            string room = "";
            string thistext = "";
            string id = js.Lookup("fldID", "tblCustomizedEvent", "fldEventCode='" + this.Text + "'");

            if(lblCount.Text==lblTotal.Text)
            {

                string qry = "SELECT er.fldRoomID,r.fldRoom FROM tblCustomizedEventRooms er " +
                              "  LEFT OUTER JOIN tblRoom r on r.fldID=er.fldRoomID" +
                               " WHERE er.fldMaxCapacity>(SELECT Count(*) FROM tblAttendance WHERE fldRoomID=er.fldRoomID AND fldLoginDateTime BETWEEN '" + DateTime.Now.ToShortDateString() + " 00:00:00' AND '" + DateTime.Now.ToShortDateString() + " 23:59:59' AND fldEventID='" + fldEventID + "')" +
                               " AND fldCEventID='" + id + "'";
                js.ExecuteQuery(qry);

                js.RiD.Read();

                if (js.RiD.HasRows)
                {
                    room = "" + js.RiD["fldRoom"].ToString();
                    roomid = js.RiD["fldRoomID"].ToString();
                }

                if(room!="")
                {
                    js.showExclamation("Room: " + txtRoom.Text + " is already maxed out the kid will be transferred to Room: " + room);
                }
                else
                {
                    room = txtRoom.Text;
                    roomid =  js.Lookup("fldID", "tblRoom", "fldRoom='" + txtRoom.Text + "'");
                    js.showExclamation("Room: " + txtRoom.Text + " is already maxed out, the kid will be added to Room: " + room);
                }

            }
               id = js.Lookup("fldID", "tblCustomizedEvent", "fldEventCode='" + this.Text + "'");

            string qq = "SELECT er.fldRoomID,r.fldRoom,er.fldAgeFrom,er.fldAgeTo FROM tblCustomizedEventRooms er " +
                              "  LEFT OUTER JOIN tblRoom r on r.fldID=er.fldRoomID" +
                               " WHERE er.fldMaxCapacity>(SELECT Count(*) FROM tblAttendance WHERE fldRoomID=er.fldRoomID AND fldLoginDateTime BETWEEN '" + DateTime.Now.ToShortDateString() + " 00:00:00' AND '" + DateTime.Now.ToShortDateString() + " 23:59:59' AND fldEventID='" + fldEventID + "')" +
                               " AND fldCEventID='" + id + "'";

            while (correct == false)
            {
                //string value = "";
                frmOverride frm = new frmOverride();
                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {

                }
                else
                {

                    checkin.frmOverFlowRoom form = new checkin.frmOverFlowRoom();
                    form.Tag = qq;
                    if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        string[] tag = form.Tag.ToString().Split(char.Parse("|"));

                        room = tag[1];
                        roomid = tag[0];
                    }
                    correct = true;
                    //return;
                }

            }

            if (System.IO.File.Exists(pathfile))
            {
                img.Image = Image.FromFile(pathfile);

                img.Image = (Image)(new Bitmap(img.Image, new Size(150, 150)));
            }
            else
            {
                img.Image = Image.FromFile(Application.StartupPath + "/Pictures/download.jpg");
                img.Image = (Image)(new Bitmap(img.Image, new Size(150, 150)));
            }

            pbImageKid.Image = img.Image;

            txtName.Text = firstname + " " + Lastname;

            txtBirthday.Text = Convert.ToDateTime(js.Lookup("fldBirthday", "tblKids", "fldID='" + pbOverride.Tag + "'")).ToShortDateString();

            DateTime sdate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd"));
            DateTime edate = sdate.AddDays(6);
            DateTime bd = Convert.ToDateTime(Convert.ToDateTime(txtBirthday.Text).ToString("MM/dd"));

            if (bd >= sdate && bd <= edate)
            {
                pbBirthday.Visible = true;
                pbPopper.Visible = true;

            }
            else
            {
                pbBirthday.Visible = false;
                pbPopper.Visible = false;
            }

            txtAllergies.Text = js.Lookup("fldAllergies", "tblKids", "fldID='" + pbOverride.Tag + "'");

            txtAge.Text = js.GetAge(Convert.ToDateTime(txtBirthday.Text)).ToString();

            txtBarcode.Text = js.Lookup("fldStudentID", "tblKids", "fldID='" + pbOverride.Tag + "'");

            txtNFC.Text = js.Lookup("fldNFCCode", "tblKidsNFC", "fldKidID='" + pbOverride.Tag + "'");

            if (Convert.ToDecimal(age) < 2)
            {
                group = 1;
            }

            else if ((Convert.ToDecimal(age) >= 2) && (Convert.ToDecimal(age) < 3))
            {
                group = 2;
            }

            else if ((Convert.ToDecimal(age) >= 3) && (Convert.ToDecimal(age) <= 4))
            {
                group = 3;
            }

            else if ((Convert.ToDecimal(age) >= 5) && (Convert.ToDecimal(age) <= 6))
            {
                group = 4;
            }

            else if ((Convert.ToDecimal(age) >= 7) && (Convert.ToDecimal(age) <= 9))
            {
                group = 5;
            }

            else if ((Convert.ToDecimal(age) >= 10) && (Convert.ToDecimal(age) <= 12))
            {
                group = 6;
            }

            else
            {
                group = 0;
            }

            string q = "INSERT INTO tblAttendance(fldRoomID,fldChurch,fldLoginDateTime,fldKidsID,fldEventID,fldGroupID,fldAge) VALUES('" + roomid + "','" + 1 + "','" + DateTime.Now.ToString() + "','" + txtBarcode.Text + "','" + fldEventID + "','" + group + "','" + age + "')";

            //string q = "INSERT INTO tblAttendance(fldRoomID,fldChurch,fldLoginDateTime,fldKidsID,fldEventID) VALUES('" + roomid + "','" + 1 + "','" + DateTime.Now.ToString() + "','" + kidid + "','" + fldEventID + "')";

            js.ExecuteNonQuery(q);

            pbLoading.Visible = true;

            if(Properties.Settings.Default.PairedDevices!="")
            {
                string[] devices = Properties.Settings.Default.PairedDevices.Split(char.Parse(","));

                if (devices[0] == "")
                {
                    string device = Properties.Settings.Default.PairedDevices;

                    string[] properties = device.Split(char.Parse("|"));

                    Connector con = new Connector(properties[1],"Kids_Checkin","kidschurch","1nt3gr1ty@ENLI");

                    try
                    {
                        Application.DoEvents();
                        con.ExecuteNonQuery(q);
                    }
                    catch(Exception ex)
                    {

                    }

                    return;
                }

                for(int i=0;i<=(devices.Length - 1);i++)
                {
                    string device = devices[i];

                    string[] properties = device.Split(char.Parse("|"));

                    Connector con = new Connector(properties[1], "Kids_Checkin", "kidschurch", "1nt3gr1ty@ENLI");

                    try
                    {
                        Application.DoEvents();
                        con.ExecuteNonQuery(q);
                    }
                    catch(Exception ex)
                    {

                    }

                }

            }

            pbLoading.Visible = false;

            thistext = this.Text;
            txtRoom.Text = room;
            this.Tag = room;
            frmLogin_Load(null, null);
            lblNotification.ForeColor = System.Drawing.Color.Green;
            lblNotification.Text = "Successfully Logged In";

            tmrReader.Enabled = true;
            pbOverride.Tag = null;
            pbOverride.Visible = false;
        }