示例#1
0
        //=====================================================================
        //כפתור לחיפוש רכבים בטבלה או על ידי תעודת זהות או על ידי מספר רכב
        //=====================================================================
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            txtNote.Text = null;
            if (searchcar.Text != "")
            {
                if (valid.checkcarId(searchcar.Text) == true) //בידקת תקינות מספר רכב
                {
                    DGcars.Rows.Clear();
                    rowIndex = 0;

                    int search;
                    int flag1 = 0;

                    search = int.Parse(searchcar.Text);
                    flag1  = dataB.CheckCarExist(search);
                    if (flag1 == 1)
                    {
                        int idcar;
                        if (int.TryParse(searchcar.Text, out idcar))
                        {
                            idcar = int.Parse(searchcar.Text);
                            showResult(idcar); // קריאה לפונקציה להוצאת נתונים
                        }
                    }
                    else
                    {
                        searchcar.BackColor = Color.Red;
                        MessageBox.Show("רכב לא קיים במערכת");
                        searchcar.BackColor = Color.White;
                        searchcar.Clear();
                        searchcar.Focus();
                        return;
                    }
                    return;
                }
            }

            //=========================
            //חיפוש על ידי תעודת זהות
            //=========================
            if (searchcar.Text != "")
            {
                if (valid.checkId(searchcar.Text) == true) // בדיקת תקינות על ידי תעודת זהות
                {
                    int search;
                    int numRow;
                    int flag1 = 0;

                    search = int.Parse(searchcar.Text);
                    flag1  = dataB.CheckCarExistbyid(search);
                    if (flag1 == 1)
                    {
                        int idcarvis;
                        if (int.TryParse(searchcar.Text, out idcarvis))
                        {
                            idcarvis = int.Parse(searchcar.Text);
                            showResultid(idcarvis); // קריאה לפונקציה להוצאת נתונים
                        }
                    }
                    else
                    {
                        searchcar.BackColor = Color.Red;
                        MessageBox.Show("רכב לא קיים במערכת");
                        searchcar.BackColor = Color.White;
                        searchcar.Clear();
                        searchcar.Focus();
                    }
                }
                else
                {
                    searchcar.BackColor = Color.Red;
                    MessageBox.Show("מספר זיהוי לא תקין");
                    searchcar.BackColor = Color.White;
                    searchcar.Clear();
                    searchcar.Focus();
                }
            }
            else
            {
                searchcar.BackColor = Color.Red;
                MessageBox.Show("נא להקליד מספר זיהוי");
                searchcar.BackColor = Color.White;
                searchcar.Focus();
            }
        }
        //============================================
        // פונקציה שרושמת את כל הכניסות מהבית חולים
        // ושומר את המידע
        //============================================
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            txtCheckInOut.Focus();
            bool   flagcarID = false; // דגל כבוי
            string crId      = string.Empty;
            int    index     = -1;

            crId = txtCheckInOut.Text;
            if (txtCheckInOut.Text.Length == 7 || txtCheckInOut.Text.Length == 8 && crId != string.Empty) // תקינות מספר רכב 7 או 8 ספרות
            {
                int search;
                int flag1 = 0;

                search = int.Parse(txtCheckInOut.Text);
                flag1  = dataB.CheckCarExist(search); // בדיקה אם הרכב קיים במערכת
                if (flag1 == 1)
                {
                    for (int i = 0; i < visit.Length; i++)
                    {
                        if (visit[i].CheckInOrCheckOut == false && visit[i].CrId.Equals(crId)) // בדיקה שהרכב לא בתוך הבית חולים וזיהוי המספר בבסיס נתונים
                        {
                            flagcarID = true;
                            index     = i;
                        }
                    }

                    if (flagcarID)
                    {
                        txtCheckInOut.Focus();
                        if (txtDesCheck.Text == string.Empty)
                        {
                            txtDesCheck.Text = "המבקר נכנס";
                        }
                        dataB.updateInsertEntery(visit[index], true, txtDesCheck.Text); // הוספה ועדכון של מבקר הנכנס לבית חולים
                        dataB.insertEvent(visit[index], true, txtDesCheck.Text);        // עדכון טבלת היסטוריה על כניסה חדשה והערה של מבקר
                        txtCheckInOut.BackColor = Color.Green;
                        var confirmResult = MessageBox.Show(" המבקר [" + txtCheckInOut.Text + "] נכנס לבית חולים", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCheckInOut.BackColor = Color.White;
                        if (confirmResult == DialogResult.OK)
                        {
                            this.Close();
                        }
                        return;
                    }
                    else
                    {
                        txtCheckInOut.BackColor = Color.Red;
                    }
                    MessageBox.Show("המבקר [" + txtCheckInOut.Text + "] כבר בפנים", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCheckInOut.BackColor = Color.White;
                }
                else
                {
                    txtCheckInOut.BackColor = Color.Red;
                    MessageBox.Show("רכב לא קיים במערכת", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCheckInOut.BackColor = Color.White;
                    txtCheckInOut.Clear();
                    txtCheckInOut.Focus();
                }
            }
            else
            {
                txtCheckInOut.BackColor = Color.Red;
                MessageBox.Show("הכנס 7 או 8 ספרות של הרכב ונסה שנית", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtCheckInOut.BackColor = Color.White;
                txtCheckInOut.Clear();
                txtCheckInOut.Focus();
            }
        }