Beispiel #1
0
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            string cardNumber = this.tbxCheckInCardNumber.Text;

            if (!this.tbxCnicNumber.MaskCompleted)
            {
                MessageBox.Show(this, "Please Enter correct CNIC NUMBER.");
                this.tbxCnicNumber.ReadOnly  = false;
                this.tbxCnicNumber.BackColor = System.Drawing.Color.White;
                return;
            }

            bool validtated = EFERTDbUtility.ValidateInputs(new List <TextBox>()
            {
                this.tbxFirstName, this.tbxCheckInCardNumber
            });

            if (validtated && this.cbxVFCategory.SelectedItem == null || string.IsNullOrEmpty(this.cbxVFCategory.SelectedItem.ToString().Trim()))
            {
                validtated = false;
            }

            if (!validtated)
            {
                MessageBox.Show(this, "Please fill mandatory fields first.");
                return;
            }

            bool isCardNotReturned = this.mCheckIns.Any(checkInInfo => checkInInfo.CheckedIn && checkInInfo.CardNumber == cardNumber);

            CCFTCentralDb.CCFTCentral ccftCentralDb = new CCFTCentralDb.CCFTCentral();
            bool cardExist = ccftCentralDb.Cardholders.Any(card => card.LastName == cardNumber);

            if (cardExist && !isCardNotReturned)
            {
                var cardAlreadyIssued = (from checkin in EFERTDbUtility.mEFERTDb.CheckedInInfos
                                         where checkin != null && checkin.CheckedIn && checkin.CardNumber == cardNumber
                                         select new
                {
                    checkin.CheckedIn,
                    checkin.CNICNumber
                }).FirstOrDefault();

                if (cardAlreadyIssued != null && cardAlreadyIssued.CheckedIn)
                {
                    MessageBox.Show(this, "This card is already issue to the person with CNIC number: " + cardAlreadyIssued.CNICNumber);
                    return;
                }
                if (this.mVisitor == null)
                {
                    VisitorCardHolder visitor = new VisitorCardHolder();

                    visitor.CNICNumber                   = this.tbxCnicNumber.Text;
                    visitor.Gender                       = this.cbxGender.SelectedItem == null ? string.Empty : this.cbxGender.SelectedItem as String;
                    visitor.FirstName                    = this.tbxFirstName.Text;
                    visitor.LastName                     = this.tbxLastName.Text;
                    visitor.Address                      = this.tbxAddress.Text;
                    visitor.PostCode                     = this.tbxPostCode.Text;
                    visitor.City                         = this.tbxCity.Text;
                    visitor.State                        = this.tbxState.Text;
                    visitor.CompanyName                  = this.tbxCompanyName.Text;
                    visitor.ContactNo                    = this.tbxPhoneNumber.Text;
                    visitor.EmergencyContantPerson       = this.tbxEmergencyContact.Text;
                    visitor.EmergencyContantPersonNumber = this.tbxEmergencyContactNumber.Text;
                    visitor.VisitorType                  = this.cbxVisitorType.SelectedItem == null ? string.Empty : this.cbxVisitorType.SelectedItem as String;
                    visitor.IsOnPlant                    = SearchForm.mIsPlant;

                    if (this.pbxSnapShot.Image != null)
                    {
                        visitor.Picture = EFERTDbUtility.ImageToByteArray(this.pbxSnapShot.Image);
                    }

                    if (this.mSchoolingStaff)
                    {
                        visitor.SchoolName = this.cbxSchoolCollege.SelectedItem == null ? string.Empty : this.cbxSchoolCollege.SelectedItem as String;
                    }

                    visitor.VisitorInfo = this.mVisitorInfo;

                    EFERTDbUtility.mEFERTDb.Visitors.Add(visitor);

                    //EFERTDbUtility.mEFERTDb.SaveChanges();

                    this.mVisitor = visitor;
                }


                CheckInAndOutInfo checkedInInfo = new CheckInAndOutInfo();

                checkedInInfo.CheckInToPlant  = SearchForm.mIsPlant;
                checkedInInfo.CheckInToPlant  = !SearchForm.mIsPlant;
                checkedInInfo.FirstName       = this.mVisitor.FirstName;
                checkedInInfo.Visitors        = this.mVisitor;
                checkedInInfo.CNICNumber      = this.mCNICNumber;
                checkedInInfo.CardNumber      = this.tbxCheckInCardNumber.Text;
                checkedInInfo.VehicleNmuber   = this.tbxCheckInVehicleNumber.Text;
                checkedInInfo.NoOfMaleGuest   = this.nuNoOfMaleGuest.Value;
                checkedInInfo.NoOfFemaleGuest = this.nuNoOfFemaleGuest.Value;
                checkedInInfo.DurationOfStay  = this.numCheckInDurationOfStay.Value;
                checkedInInfo.NoOfChildren    = this.nuCheckInNoOfChildren.Value;
                checkedInInfo.AreaOfVisit     = this.cbxAreaOfVisit.SelectedItem == null ? string.Empty : this.cbxAreaOfVisit.SelectedItem as String;
                checkedInInfo.HostName        = this.tbxCheckInHostName.Text;
                checkedInInfo.DateTimeIn      = Convert.ToDateTime(this.tbxCheckInDateTimeIn.Text);
                checkedInInfo.DateTimeOut     = DateTime.MaxValue;
                checkedInInfo.CheckedIn       = true;
                checkedInInfo.Category        = this.mVisitorInfo;

                try
                {
                    EFERTDbUtility.mEFERTDb.CheckedInInfos.Add(checkedInInfo);
                    EFERTDbUtility.mEFERTDb.SaveChanges();
                }
                catch (Exception ex)
                {
                    EFERTDbUtility.RollBack();

                    MessageBox.Show(this, "Some error occurred in issuing card.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex));
                    return;
                }

                this.btnCheckIn.Enabled  = false;
                this.btnCheckOut.Enabled = true;

                this.Close();
            }
            else
            {
                if (!cardExist)
                {
                    MessageBox.Show(this, "Please enter valid card number.");
                }
                else if (isCardNotReturned)
                {
                    MessageBox.Show(this, "Card is already issued to some one else.");
                }
            }
        }
Beispiel #2
0
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            string cardNumber = this.tbxCheckInCardNumber.Text;

            if (string.IsNullOrEmpty(cardNumber))
            {
                MessageBox.Show(this, "Card number can not be empty.");
                return;
            }

            bool isCardNotReturned = this.mCheckIns.Any(checkInInfo => checkInInfo.CheckedIn && checkInInfo.CardNumber == cardNumber);

            bool cardExist = false;

            CCFTCentralDb.CCFTCentral ccftCentralDb = new CCFTCentralDb.CCFTCentral();
            cardExist = ccftCentralDb.Cardholders.Any(card => card.LastName == cardNumber);
            CardHolderInfo cardHolderInfo = this.mCardHolderInfo;

            if (cardExist && !isCardNotReturned)
            {
                var cardAlreadyIssued = (from checkin in EFERTDbUtility.mEFERTDb.CheckedInInfos
                                         where checkin != null && checkin.CheckedIn && checkin.CardNumber == cardNumber
                                         select new
                {
                    checkin.CheckedIn,
                    checkin.CNICNumber
                }).FirstOrDefault();

                if (cardAlreadyIssued != null && cardAlreadyIssued.CheckedIn)
                {
                    MessageBox.Show(this, "This card is already issue to the person with CNIC number: " + cardAlreadyIssued.CNICNumber);
                    return;
                }


                if (cardHolderInfo == null)
                {
                    MessageBox.Show(this, "Unable to Issue Card. Some error occured in getting cardholder information.");
                    return;
                }

                CheckInAndOutInfo checkedInInfo = new CheckInAndOutInfo();

                checkedInInfo.CheckInToPlant  = SearchForm.mIsPlant;
                checkedInInfo.CheckInToColony = !SearchForm.mIsPlant;
                checkedInInfo.FirstName       = cardHolderInfo.FirstName;
                checkedInInfo.CardHolderInfos = cardHolderInfo;
                checkedInInfo.CNICNumber      = this.mCNICNumber;
                checkedInInfo.CardNumber      = cardNumber;
                checkedInInfo.VehicleNmuber   = this.tbxCheckInVehicleNumber.Text;
                checkedInInfo.DateTimeIn      = Convert.ToDateTime(this.tbxCheckInDateTimeIn.Text);
                checkedInInfo.DateTimeOut     = DateTime.MaxValue;
                checkedInInfo.CheckedIn       = true;

                try
                {
                    EFERTDbUtility.mEFERTDb.CheckedInInfos.Add(checkedInInfo);
                    EFERTDbUtility.mEFERTDb.SaveChanges();
                }
                catch (Exception ex)
                {
                    EFERTDbUtility.RollBack();

                    MessageBox.Show(this, "Some error occurred in issuing card.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex));
                    return;
                }

                this.btnCheckIn.Enabled  = false;
                this.btnCheckOut.Enabled = true;



                this.Close();
            }
            else
            {
                if (!cardExist)
                {
                    MessageBox.Show(this, "Please enter valid card number.");
                }
                else if (isCardNotReturned)
                {
                    MessageBox.Show(this, "Card is already issued to some one else.");
                }
            }
        }