示例#1
0
        public static void SetBackDocForBudgetInEntryView()
        {
            if (!MainClass.IsPasha())
            {
                return;
            }

            using (PriemEntities context = new PriemEntities())
            {
                if (MessageBox.Show("Проставить 'Забрал документы' для платных заявлений, поступивших на бесплатное?", "Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromHours(1)))
                    {
                        var abits = from ev in context.extEntryView
                                    join ab in context.extAbit
                                    on ev.AbiturientId equals ab.Id
                                    where ab.StudyLevelGroupId == 1 && ab.StudyBasisId == 1 && !ab.BackDoc && ab.HasOriginals
                                    select ab;

                        foreach (extAbit abit in abits)
                        {
                            var abBackDocks = from ab in context.extAbit
                                              where ab.StudyLevelGroupId == abit.StudyLevelGroupId &&
                                              ab.IsReduced == abit.IsReduced && ab.IsParallel == abit.IsParallel && ab.IsSecond == abit.IsSecond &&
                                              ab.FacultyId == abit.FacultyId && ab.LicenseProgramId == abit.LicenseProgramId &&
                                              ab.ObrazProgramId == abit.ObrazProgramId &&
                                              (abit.ProfileId == null ? ab.ProfileId == null : ab.ProfileId == abit.ProfileId) &&
                                              ab.StudyFormId == abit.StudyFormId &&
                                              ab.StudyBasisId == 2
                                              select ab;

                            if (abBackDocks.Count() > 0)
                            {
                                foreach (extAbit abBack in abBackDocks)
                                {
                                    context.Abiturient_UpdateBackDoc(true, DateTime.Now, abBack.Id);
                                }
                            }
                        }


                        transaction.Complete();
                    }
                }
            }
        }
        private void btnLoad_Click(object sender, EventArgs e)
        {
            int?changeTp = ChangeTypeId;

            foreach (DataGridViewRow dgvr in dgvAbiturients.SelectedRows)
            {
                string code    = dgvr.Cells["Barcode"].Value.ToString();
                string perCode = dgvr.Cells["PersonBarcode"].Value.ToString();

                try
                {
                    int abitBarcode;
                    int persBarcode;

                    if (!int.TryParse(code, out abitBarcode))
                    {
                        WinFormsServ.Error("Не распознан баркод!");
                        return;
                    }

                    if (abitBarcode == 0)
                    {
                        WinFormsServ.Error("Не распознан баркод!");
                        return;
                    }

                    if (!int.TryParse(perCode, out persBarcode))
                    {
                        WinFormsServ.Error("Не распознан баркод!");
                        return;
                    }

                    if (persBarcode == 0)
                    {
                        WinFormsServ.Error("Не распознан баркод!");
                        return;
                    }

                    ChangeAbitClass chCl;

                    string updateQuery = string.Empty;

                    switch (changeTp)
                    {
                    // приоритеты
                    case 1:
                    {
                        if (!MessageAttention())
                        {
                            return;
                        }

                        chCl = lstAbits[abitBarcode];

                        using (PriemEntities context = new PriemEntities())
                        {
                            Guid abitId = (from ab in context.extAbit
                                           where ab.Barcode == abitBarcode
                                           select ab.Id).FirstOrDefault();
                            double pr;
                            if (!double.TryParse(chCl.Priority, out pr))
                            {
                                break;
                            }

                            context.Abiturient_UpdatePriority(pr, abitId);
                            break;
                        }
                    }

                    // забрал доки в инете
                    case 2:
                    {
                        if (!MessageAttention())
                        {
                            return;
                        }

                        chCl = lstAbits[abitBarcode];
                        DataRow  dr       = _bdcInet.GetDataSet(string.Format("SELECT qAbiturient.BackDocDate FROM qAbiturient WHERE Barcode = {0}", abitBarcode)).Tables[0].Rows[0];
                        DateTime?backDate = dr.Field <DateTime?>("BackDocDate");

                        using (PriemEntities context = new PriemEntities())
                        {
                            Guid abitId = (from ab in context.extAbit
                                           where ab.Barcode == abitBarcode
                                           select ab.Id).FirstOrDefault();

                            context.Abiturient_UpdateBackDoc(true, backDate, abitId);
                            break;
                        }
                    }

                    // забрал доки в нашей базе
                    case 3:
                    {
                        if (!MessageAttention())
                        {
                            return;
                        }

                        chCl = lstAbits[abitBarcode];
                        DataRow  dr       = _bdc.GetDataSet(string.Format("SELECT qAbiturient.BackDocDate FROM ed.qAbiturient WHERE Barcode = {0}", abitBarcode)).Tables[0].Rows[0];
                        DateTime?backDate = dr.Field <DateTime?>("BackDocDate");
                        updateQuery = string.Format("UPDATE qAbiturient SET Enabled = 0, DateOfDisable = '{1}' WHERE Barcode = {0}", abitBarcode, backDate == null ? "NULL" : backDate.Value.Date.ToShortDateString());
                        _bdcInet.ExecuteQuery(updateQuery);
                        break;
                    }

                    // новые документы
                    case 4:
                    {
                        new DocCard(persBarcode, abitBarcode, true, MainClass.dbType == PriemType.PriemForeigners).ShowDialog();
                        break;
                    }
                    }
                }
                catch (Exception ex)
                {
                    WinFormsServ.Error("Ошибка обновления данных: " + code + ":" + ex.Message);
                    goto Next;
                }
                Next :;
            }
            UpdateDataGrid();
        }