示例#1
0
        private void tnSubmit_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgvItem.Rows.Count; i++)
            {
                ChangedPart cp = new ChangedPart();
                cp.EmergencyMaintenanceID = emergencyMaintenance.ID;
                cp.PartID = (cbPart.SelectedItem as Part).ID;
                cp.Amount = Convert.ToDouble(dgvItem.Rows[i].Cells["Amount"].Value);

                db.ChangedParts.Add(cp);
            }
            emergencyMaintenance = db.EmergencyMaintenances.Where(x => x.ID == emergencyMaintenance.ID).SingleOrDefault();
            emergencyMaintenance.EMTechinicianNote = txtNote.Text;
            try
            {
                if (dpkEndDate.Text != "  -  -")
                {
                    DateTime endDate = Convert.ToDateTime(dpkEndDate.Text);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("End date is invalid");
                return;
            }
            emergencyMaintenance.EMStartDate = dpkStartDate.Value;
            if (dpkEndDate.Text != "  -  -")
            {
                emergencyMaintenance.EMEndDate = Convert.ToDateTime(dpkEndDate.Text);
            }
            db.SaveChanges();
            MessageBox.Show("Submit successfully");
        }
        private void btnSendRequest_Click(object sender, EventArgs e)
        {
            if (txtDescription.Text.Trim() == "" || txtOtherConsiderations.Text.Trim() == "")
            {
                MessageBox.Show("A field is empty!");
                return;
            }
            //check asset is opening or not?
            EmergencyMaintenance temp = db.EmergencyMaintenances.Where(x => x.AssetID == selectedAsset.ID && x.EMReportDate != null && x.EMEndDate == null).FirstOrDefault();

            if (temp != null)
            {
                MessageBox.Show("This asset is opening on system");
                return;
            }
            EmergencyMaintenance em = new EmergencyMaintenance();

            em.AssetID              = this.selectedAsset.ID;
            em.PriorityID           = (cbPriority.SelectedItem as Priority).ID;
            em.DescriptionEmergency = txtDescription.Text;
            em.OtherConsiderations  = txtOtherConsiderations.Text;
            em.EMReportDate         = DateTime.Now;
            db.EmergencyMaintenances.Add(em);
            db.SaveChanges();
            MessageBox.Show("Send request successfully");
        }
示例#3
0
 private int Compare(EmergencyMaintenance a, EmergencyMaintenance b)
 {
     if (a.PriorityID < b.PriorityID)
     {
         return(-1);
     }
     else if (a.PriorityID > b.PriorityID)
     {
         return(1);
     }
     else
     {
         DateTime aa = Convert.ToDateTime(a.EMReportDate);
         DateTime bb = Convert.ToDateTime(b.EMReportDate);
         return(aa.CompareTo(bb));
     }
 }