Пример #1
0
        private void btnSendSelectedShifts_Click(object sender, EventArgs e)
        {
            List <int> ids = new List <int>();

            foreach (DataGridViewRow row in dgvShifts.SelectedRows)
            {
                ids.Add((int)row.Cells["colID"].Value);
            }

            int remoteUserID      = frmRemoteLogin.RemoteUserID;
            List <RemoteShift> ls = (from s in ctx.Shifts
                                     where ids.Contains(s.ID)
                                     select new RemoteShift
            {
                Date = s.Date,
                ShiftNum = s.ShiftNum,
                RemoteUserID = remoteUserID,
                Description = s.Description,
                RemoteRequests = (from r in s.Requests
                                  select new RemoteRequest
                {
                    FullName = r.Passenger.FullName,
                    Gender = r.Passenger.Gender,
                    PassportNum = r.Passenger.PassportNum,
                    BornDate = r.Passenger.BornDate,
                    IssueDate = r.Passenger.IssueDate,
                    ExpiryDate = r.Passenger.ExpiryDate
                }).ToList <RemoteRequest>()
            }).ToList <RemoteShift>();

            ctxCentral.RemoteShifts.AddRange(ls);
            ctxCentral.RemoteUsers.Where(u => u.ID == remoteUserID).First <RemoteUser>().LastSeen = DateTime.Now;

            try
            {
                ctxCentral.SaveChanges();
            }
            catch (System.Data.Entity.Core.EntityException ex)
            {
                if (ex.InnerException.HResult == -2146232060)
                {
                    MessageBox.Show("اتصال به پایگاه داده برقرار نشد. لطفا از اتصال به اینترنت مطمئن شوید...\n" + ex.ToString());
                }
                ctxCentral = new VisaXCenteralEntities("ASAWARI");
                return;
            }

            foreach (var shift in ctx.Shifts.Select(s => s).Where(ss => ids.Contains(ss.ID)))
            {
                shift.Sent = true;
            }
            ctx.SaveChanges();

            MessageBox.Show("شیفت های منتخب با موفقیت به مرکز ارسال شدند.", "ارسال شیفت های منتخب", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.RtlReading);
            refreshGrid();
        }
Пример #2
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();
        }