Exemple #1
0
 public frmRenameUser(User usr, VisaXEntities ctx) : this()
 {
     CurrentUser      = usr;
     this.ctx         = ctx;
     txtUserName.Text = CurrentUser.UserName;
     txtFullName.Text = CurrentUser.RealName;
 }
Exemple #2
0
        }//btnEdit

        private void btnList_Click(object sender, EventArgs e)
        {
            ctx = new VisaXEntities();
            int   id    = int.Parse(dgvShifts.SelectedRows[0].Cells["colID"].Value.ToString());
            Shift shift = (from s in ctx.Shifts where s.ID == id select s).First();

            new frmRequests(shift).ShowDialog();
            int selShift = dgvShifts.SelectedRows[0].Index;

            refreshGrid();
            dgvShifts.Rows[selShift].Selected = true;
        }
Exemple #3
0
        private void send()
        {
            VisaXCenteralEntities ctxRemote = new VisaXCenteralEntities("ASAWARI");
            VisaXEntities         ctxLocal  = new VisaXEntities();
            var locals  = ctxLocal.Passengers.ToList();
            var remotes = ctxRemote.RemotePassengers.ToList();

            var newPassengers = locals.Where(l => !remotes.Any(r => r.PassportNum == l.PassportNum)).Select(p => new RemotePassenger()
            {
                PassportNum = p.PassportNum,
                FullName    = p.FullName,
                Gender      = p.Gender,
                BornDate    = p.BornDate,
                IssueDate   = p.IssueDate,
                ExpiryDate  = p.ExpiryDate
            }).ToList();

            ctxRemote.RemotePassengers.AddRange(newPassengers);
            ctxRemote.SaveChanges();
        }
Exemple #4
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            ctx = new VisaXEntities();
            int         id          = (int)dgvShifts.SelectedRows[0].Cells["colID"].Value;
            Shift       shift       = (from s in ctx.Shifts where s.ID == id select s).First();
            string      message     = string.Format("ویرایش توضیحات شیفت شماره {0} با تاریخ {1} توسط {2}؟", shift.ShiftNum, shift.Date.ToShortDateString(), shift.User.RealName);
            frmNewShift frmNewShift = new frmNewShift(message);

            frmNewShift.txtDescription.Text = shift.Description;
            if (frmNewShift.ShowDialog() == DialogResult.Yes)
            {
                shift.Description = frmNewShift.txtDescription.Text;
            }

            ctx.SaveChanges();
            refreshGrid();

            dgvShifts.ClearSelection();
            dgvShifts.Rows[dgvShifts.RowCount - 1].Selected = true;
        }//btnEdit
Exemple #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string sucMessage = string.Empty;

            if (validateForm())
            {
                if (this.passenger == null) //if Add mode
                {
                    Passenger p = new Passenger
                    {
                        FullName    = txtFullName.Text,
                        PassportNum = txtPassportNum.Text,
                        Gender      = (byte)cmbGender.SelectedIndex,
                        UserID      = Properties.Settings.Default.User.ID
                    };

                    DateTime tempDate;
                    if (DateTime.TryParse(txtBornDate.Text, out tempDate))
                    {
                        p.BornDate = tempDate;
                    }
                    if (DateTime.TryParse(txtIssueDate.Text, out tempDate))
                    {
                        p.IssueDate = tempDate;
                    }
                    if (DateTime.TryParse(txtExpiryDate.Text, out tempDate))
                    {
                        p.ExpiryDate = tempDate;
                    }

                    p.Requests.Add(new Request
                    {
                        ShiftID = this.selectedShift.ID,
                        UserID  = Properties.Settings.Default.User.ID,
                    });

                    ctx.Passengers.Add(p);

                    sucMessage             = "رکورد جدید اضافه شد";
                    lblStatusMsg.ForeColor = Color.DarkGreen;
                    lblStatusMsg.Text      = string.Format("{0} ({1})", sucMessage, p.FullName);
                }
                else //if edit mode
                {
                    this.passenger.FullName    = txtFullName.Text;
                    this.passenger.PassportNum = txtPassportNum.Text;
                    this.passenger.Gender      = (byte)cmbGender.SelectedIndex;
                    DateTime tempDate;

                    if (DateTime.TryParse(txtBornDate.Text, out tempDate))
                    {
                        passenger.BornDate = tempDate;
                    }
                    if (DateTime.TryParse(txtIssueDate.Text, out tempDate))
                    {
                        passenger.IssueDate = tempDate;
                    }
                    if (DateTime.TryParse(txtExpiryDate.Text, out tempDate))
                    {
                        passenger.ExpiryDate = tempDate;
                    }

                    this.passenger.UserID = Properties.Settings.Default.User.ID;

                    sucMessage             = "رکورد ویرایش شد";
                    lblStatusMsg.ForeColor = Color.DarkBlue;
                    lblStatusMsg.Text      = string.Format("{0} ({1})", sucMessage, passenger.FullName);
                    if (!this.justEdit)
                    {
                        this.passenger.Requests.Add(new Request
                        {
                            ShiftID = this.selectedShift.ID,
                            UserID  = Properties.Settings.Default.User.ID
                        });
                    }
                }//else

                try
                {
                    ctx.SaveChanges();
                }
                catch (System.Data.Entity.Infrastructure.DbUpdateException ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("AK_Date_PassengerID"))
                    {
                        new frmMsgBox(ex.ToString(), "متقاضی مورد نظر قبلاً در این روز ثبت شده.", MessageBoxButtons.OK, MsgBoxIcon.Stop).ShowDialog();
                    }
                    ctx = new VisaXEntities();
                }
                this.passenger = null;
                txtPassportNum.Focus();
                txtFullName.Text = txtPassportNum.Text = txtBornDate.Text = txtExpiryDate.Text = txtIssueDate.Text = string.Empty;
            }//if
        }
Exemple #6
0
        private void import()
        {
            int invalidDates = 0;

            if (txtFileName.Text == string.Empty)
            {
                MessageBox.Show("ابتدا پوشه حاوی فایل های اکسل را انتخاب کنید.", "وارد کردن متقاضیان به دیتابیس", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                btnBrowse_Click(null, null);
            }//if

            List <Passenger> allPassengers = new List <Passenger>();
            DirectoryInfo    info          = new DirectoryInfo(txtFileName.Text);
            var files = info.GetFiles("*.xls");

            Excel.Application excelApllication = null;
            Excel.Workbook    excelWorkBook    = null;
            Excel.Worksheet   excelWorkSheet   = null;
            excelApllication = new Excel.Application();
            System.Threading.Thread.Sleep(2000);
            double fileNum = 0;

            foreach (var file in files)
            {
                fileNum++;
                excelWorkBook  = excelApllication.Workbooks.Open(file.FullName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                excelWorkSheet = (Excel.Worksheet)excelWorkBook.Worksheets.get_Item(1);
                int rowNum = 1;
                while (excelWorkSheet.Cells[rowNum + 7, 8].Value != null)
                {
                    string passportNum = excelWorkSheet.Cells[rowNum + 7, 7].Value.ToString();
                    if (allPassengers.Select(r => r.PassportNum).Contains(passportNum) || passportNum.Length != 8)
                    {
                        rowNum++;
                        continue;
                    }//if

                    Passenger p = new Passenger()
                    {
                        PassportNum = passportNum,
                        FullName    = excelWorkSheet.Cells[rowNum + 7, 8].Value,
                        Gender      = (byte)(excelWorkSheet.Cells[rowNum + 7, 6].Value2 == "ذکر" ? 0 : 1),
                        UserID      = Properties.Settings.Default.User.ID
                    };

                    if (excelWorkSheet.Cells[rowNum + 7, 5].Value != null)
                    {
                        var bornDate   = excelWorkSheet.Cells[rowNum + 7, 5].Value2;
                        var issueDate  = excelWorkSheet.Cells[rowNum + 7, 4].Value2;
                        var expiryDate = excelWorkSheet.Cells[rowNum + 7, 3].Value2;

                        if (bornDate is double && issueDate is double && expiryDate is double)
                        {
                            p.BornDate   = DateTime.FromOADate(bornDate);
                            p.IssueDate  = DateTime.FromOADate(issueDate);
                            p.ExpiryDate = DateTime.FromOADate(expiryDate);
                        }//if
                        else
                        {
                            invalidDates++;
                        }
                    }//if

                    allPassengers.Add(p);
                    rowNum++;
                }//while
                int pr = (int)(fileNum / files.Count() * 100);
                bgw.ReportProgress(pr);
            }//foreach

            excelWorkBook.Close();
            excelApllication.Quit();
            Marshal.FinalReleaseComObject(excelWorkSheet);
            Marshal.FinalReleaseComObject(excelWorkBook);
            Marshal.FinalReleaseComObject(excelApllication);
            excelApllication = null;
            excelWorkSheet   = null;

            VisaXEntities ctx              = new VisaXEntities();
            var           dbPassengers     = ctx.Passengers.Select(pp => pp.PassportNum).ToList();
            var           uniquePassengers = new List <Passenger>();

            foreach (var p in allPassengers)
            {
                if (!dbPassengers.Contains(p.PassportNum))
                {
                    uniquePassengers.Add(p);
                }
            }

            if (uniquePassengers.Count == 0)
            {
                MessageBox.Show("هیچ رکورد جدیدِی برای وارد کردن وجود ندارد.", "", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading);
                return;
            }//if

            StringBuilder msg = new StringBuilder();

            msg.AppendLine("تعداد رکوردهای با تاریخ نامعتبر " + invalidDates.ToString());
            msg.AppendLine((allPassengers.Count - uniquePassengers.Count) > 0 ? string.Format("تعداد {0} متقاضی قبلا وارد شده اند.\n", allPassengers.Count - uniquePassengers.Count) : "");
            foreach (var p in uniquePassengers)
            {
                msg.AppendLine(string.Format("- {0}\t ش.پ: {1}", p.FullName, p.PassportNum));
            }

            if (new frmMsgBox(msg.ToString(), " متقاضیانی که وارد خواهند شد به شرح ذیل هستند؛ آیا مایل به وارد کردن آنها هستید؟", MessageBoxButtons.YesNo, MsgBoxIcon.Question).ShowDialog() == DialogResult.Yes)
            {
                ctx.Passengers.AddRange(uniquePassengers);
                ctx.SaveChanges();
            }//if

            Properties.Settings.Default.Save();
        }