Esempio n. 1
0
        private void teacherChoosingComboBox_SelectionChangeCommitted(object sender, EventArgs e)
        {
            int GroupSubjectId = (int)this.parent.cache.Rows[iupParams.RowIndex].ItemArray[1];
            int TeacherId      = (int)this.teacherChoosingComboBox.SelectedValue;

            if (TeacherId <= 0)
            {
                return;
            }

            tbLectureQty.Clear();
            tbSeminarQty.Clear();
            tbLabQty.Clear();
            tbEducCred.Clear();
            tbPedagCred.Clear();
            tbGradCred.Clear();
            tbIndustCred.Clear();
            tbResearchCred.Clear();
            tbMemberCred.Clear();
            tbSupervCred.Clear();
            labelAllCred.Text = string.Empty;

            oldLectureCredits    = 0;
            oldSeminarCredits    = 0;
            oldLaboratoryCredits = 0;
            oldOtherCredits      = 0;

            Curriculum existed = context.Curriculums.SingleOrDefault(c => c.GroupSubjectId == GroupSubjectId && c.TeacherId == TeacherId);

            if (existed != null)
            {
                oldLectureCredits    = existed.LectureCredits;
                oldSeminarCredits    = existed.SeminarCredits;
                oldLaboratoryCredits = existed.LaboratoryCredits;
                oldOtherCredits      = existed.EducationalPractice + existed.PedagogicalPractice + existed.UndergraduatePractice +
                                       existed.IndustrialPractice + existed.ResearchPractice + existed.СommissionMembership + existed.SupervisoryWork;

                tbLectureQty.Text   = existed.LectureCredits.ToString();
                tbSeminarQty.Text   = existed.SeminarCredits.ToString();
                tbLabQty.Text       = existed.LaboratoryCredits.ToString();
                tbEducCred.Text     = existed.EducationalPractice.ToString();
                tbPedagCred.Text    = existed.PedagogicalPractice.ToString();
                tbGradCred.Text     = existed.UndergraduatePractice.ToString();
                tbIndustCred.Text   = existed.IndustrialPractice.ToString();
                tbResearchCred.Text = existed.ResearchPractice.ToString();
                tbMemberCred.Text   = existed.СommissionMembership.ToString();
                tbSupervCred.Text   = existed.SupervisoryWork.ToString();
                SumUpAllCredits();
            }
        }
Esempio n. 2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            int        GroupSubjectId = (int)this.parent.cache.Rows[iupParams.RowIndex].ItemArray[1];
            int        TeacherId      = (int)this.teacherChoosingComboBox.SelectedValue;
            Curriculum existed        = context.Curriculums.SingleOrDefault(c => c.GroupSubjectId == GroupSubjectId && c.TeacherId == TeacherId);

            decimal lectureCredits  = decimal.Parse(string.IsNullOrWhiteSpace(tbLectureQty.Text) ? "0" : tbLectureQty.Text);
            decimal seminarCredits  = decimal.Parse(string.IsNullOrWhiteSpace(tbSeminarQty.Text) ? "0" : tbSeminarQty.Text);
            decimal laborCredits    = decimal.Parse(string.IsNullOrWhiteSpace(tbLabQty.Text) ? "0" : tbLabQty.Text);
            decimal educCredits     = decimal.Parse(string.IsNullOrWhiteSpace(tbEducCred.Text) ? "0" : tbEducCred.Text);
            decimal pedagCredits    = decimal.Parse(string.IsNullOrWhiteSpace(tbPedagCred.Text) ? "0" : tbPedagCred.Text);
            decimal gradCredits     = decimal.Parse(string.IsNullOrWhiteSpace(tbGradCred.Text) ? "0" : tbGradCred.Text);
            decimal industCredits   = decimal.Parse(string.IsNullOrWhiteSpace(tbIndustCred.Text) ? "0" : tbIndustCred.Text);
            decimal researchCredits = decimal.Parse(string.IsNullOrWhiteSpace(tbResearchCred.Text) ? "0" : tbResearchCred.Text);
            decimal memberCredits   = decimal.Parse(string.IsNullOrWhiteSpace(tbMemberCred.Text) ? "0" : tbMemberCred.Text);
            decimal supervCredits   = decimal.Parse(string.IsNullOrWhiteSpace(tbSupervCred.Text) ? "0" : tbSupervCred.Text);

            decimal cacheLectures = (decimal)parent.cache.Rows[iupParams.RowIndex].ItemArray[14];
            decimal cacheSeminars = (decimal)parent.cache.Rows[iupParams.RowIndex].ItemArray[15];
            decimal cacheLabors   = (decimal)parent.cache.Rows[iupParams.RowIndex].ItemArray[16];
            decimal cacheOthers   = (decimal)parent.cache.Rows[iupParams.RowIndex].ItemArray[17];

            Subject subj     = context.GroupSubjects.Find(GroupSubjectId).Subject;
            decimal residual = cacheLectures + oldLectureCredits - lectureCredits;

            parent.cache.Rows[iupParams.RowIndex][14] = residual;
            parent.dataGridView1.Rows[iupParams.RowIndex].Cells[10].Value = (decimal)residual;
            subj.LectureCreditQty = residual;

            residual = cacheSeminars + oldSeminarCredits - seminarCredits;
            parent.cache.Rows[iupParams.RowIndex][15] = residual;
            parent.dataGridView1.Rows[iupParams.RowIndex].Cells[11].Value = (decimal)residual;
            subj.SeminarCreditQty = residual;

            residual = cacheLabors + oldLaboratoryCredits - laborCredits;
            parent.cache.Rows[iupParams.RowIndex][16] = residual;
            parent.dataGridView1.Rows[iupParams.RowIndex].Cells[12].Value = (decimal)residual;
            subj.LaboratoryCreditQty = residual;

            residual = cacheOthers + oldOtherCredits - educCredits - pedagCredits - gradCredits - industCredits - researchCredits - memberCredits - supervCredits;
            if (residual < 0)
            {
                this.errorProvider1.SetError(addButton, "Значение введенных кредитов превышает максимальное значение дополнительных кредитов");
            }
            subj.OtherCreditQty = residual;

            context.Entry(subj).State = System.Data.Entity.EntityState.Modified;

            if (existed == null)
            {
                context.Curriculums.Add(new Curriculum()
                {
                    GroupSubjectId        = GroupSubjectId,
                    TeacherId             = TeacherId,
                    LectureCredits        = lectureCredits,
                    SeminarCredits        = seminarCredits,
                    LaboratoryCredits     = laborCredits,
                    EducationalPractice   = educCredits,
                    PedagogicalPractice   = pedagCredits,
                    UndergraduatePractice = gradCredits,
                    IndustrialPractice    = industCredits,
                    ResearchPractice      = researchCredits,
                    СommissionMembership  = memberCredits,
                    SupervisoryWork       = supervCredits
                });
            }
            else
            {
                existed.LectureCredits        = lectureCredits;
                existed.SeminarCredits        = seminarCredits;
                existed.LaboratoryCredits     = laborCredits;
                existed.EducationalPractice   = educCredits;
                existed.PedagogicalPractice   = pedagCredits;
                existed.UndergraduatePractice = gradCredits;
                existed.IndustrialPractice    = industCredits;
                existed.ResearchPractice      = researchCredits;
                existed.СommissionMembership  = memberCredits;
                existed.SupervisoryWork       = supervCredits;

                decimal all = SumUpAllCredits();
                if (all == 0)
                {
                    context.Entry(existed).State = System.Data.Entity.EntityState.Deleted;
                }
            }

            context.SaveChanges();
            parent.dataGridView1.Update();
            this.Close();
        }