예제 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtMaintenanceNr.Text.Trim().Length == 0 || Convert.ToInt32(this.comFailure.SelectedValue) == -1)
            {
                MessageBox.Show("Nie wprowadzono wartości!");
                return;
            }
            if ((this.dtpStartDate.Value.Date + this.tpStartDate.Value.TimeOfDay) >
                (this.dtpEndDate.Value.Date + this.tpEndDate.Value.TimeOfDay))
            {
                MessageBox.Show("'Data od' musi być mniejsza od 'Data do'!");
                return;
            }
            try
            {
                failureMaintenance.IdMaintenance = this.maintenance.IdMaintenance;
                int failureId = Convert.ToInt32(this.comFailure.SelectedValue);
                failureMaintenance.IdFailure = failureId;
                vMachineFailure machineFailureItem = this.db.vMachineFailures.First(machineFailure => machineFailure.IdFailure == failureId);
                maintenance.IdMachine            = machineFailureItem.IdMachine;
                this.maintenance.IdMaintType     = 1;
                this.maintenance.IdMaintDesc     = null;
                this.maintenance.DateAcceptOrder = DateTime.Now;
                this.maintenance.StartDatePlan   = this.dtpStartDate.Value.Date + this.tpStartDate.Value.TimeOfDay;
                this.maintenance.EndDatePlan     = this.dtpEndDate.Value.Date + this.tpEndDate.Value.TimeOfDay;
                this.maintenance.MaintenanceNr   = "AWR" + this.txtMaintenanceNr.Text.Trim();

                if (maintenance.IdMaintenance == 0)//Instert
                {
                    this.db.Maintenances.Add(maintenance);
                }
                else //update
                {
                    this.db.Entry(maintenance).State = EntityState.Modified;
                }
                if (failureMaintenance.IdMaintenance == 0)//Instert
                {
                    this.db.FailureMaintenances.Add(failureMaintenance);
                }
                else //update
                {
                    this.db.Entry(failureMaintenance).State = EntityState.Modified;
                }
                this.db.SaveChanges();
                MessageBox.Show("Obsługa została dodana!");
                this.btnSave.Text = "Aktualizuj";
            }
            catch (Exception)
            {
                MessageBox.Show("Wprowadź poprawną wartość!");
            }
        }
예제 #2
0
 private void comFailure_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (isLoading)
     {
         return;
     }
     else
     {
         int failureId = Convert.ToInt32(this.comFailure.SelectedValue);
         if (failureId == -1)
         {
             this.txtMachine.Text = string.Empty;
             return;
         }
         vMachineFailure machineFailureItem = this.db.vMachineFailures.First(machineFailure => machineFailure.IdFailure == failureId);
         maintenance.IdMachine = machineFailureItem.IdMachine;
         this.txtMachine.Text  = machineFailureItem.MachineName;
     }
 }