Beispiel #1
0
 private void InButton_Click(object sender, EventArgs e)
 {
     Thread.Sleep(1000);
     if (CheckDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if (CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[8].Value == null ||
                 ((DateTime)CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[8].Value < (DateTime)CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[9].Value))
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         rq.FFACTDATEBEGIN = DateTime.Now;
                         rq.FSTATUS        = Status.ActiveInput;
                         rq.FFACTDATEEND   = rq.FWHDATEBEGIN = rq.FWHDATEEND = null;
                         rq.FWHCOMMENT     = rq.FWHPERSON = null;
                     }
                     InOut io = new InOut
                     {
                         FID            = id,
                         FFACTDATEBEGIN = DateTime.Now
                     };
                     db.InOut.Add(io);
                     db.SaveChanges();
                 }
                 FillCheck();
             }
         }
     }
 }
Beispiel #2
0
 private void OutButton_Click(object sender, EventArgs e)
 {
     Thread.Sleep(1000);
     if (CheckDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if ((CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[8].Value != null && CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[9].Value == null) ||
                 (DateTime)CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[8].Value > (DateTime)CheckDGV.Rows[CheckDGV.SelectedRows[0].Index].Cells[9].Value)
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         rq.FFACTDATEEND = DateTime.Now;
                         rq.FSTATUS      = Status.ActiveOutput;
                     }
                     var io = db.InOut.Where(x => x.FID == id)
                              .Where(x => x.FFACTDATEEND == null)
                              .FirstOrDefault();
                     if (io != null)
                     {
                         io.FFACTDATEEND = DateTime.Now;
                     }
                     db.SaveChanges();
                 }
                 FillCheck();
             }
         }
     }
 }
 private void ConfirmButton_Click(object sender, EventArgs e)
 {
     if (RequestDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(RequestDGV.Rows[RequestDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if (MessageBox.Show("Утвердить заявку № " + id.ToString() + "?",
                                 "Утверждение",
                                 MessageBoxButtons.OKCancel,
                                 MessageBoxIcon.Information) == DialogResult.OK)
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         rq.FSTATUS  = Status.Approved;
                         rq.FUTVDATE = DateTime.Now;
                         db.SaveChanges();
                     }
                 }
                 FillRequestDGV();
             }
         }
     }
 }
 private void DeleteButton_Click(object sender, EventArgs e)
 {
     if (RequestDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(RequestDGV.Rows[RequestDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if (MessageBox.Show("Вы действительно хотите удалить заявку № " + id.ToString() + "?",
                                 "Удаление",
                                 MessageBoxButtons.OKCancel,
                                 MessageBoxIcon.Warning) == DialogResult.OK)
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         db.Request.Remove(rq);
                         db.SaveChanges();
                     }
                 }
                 FillRequestDGV();
             }
         }
     }
 }
 private void OutButton_Click(object sender, EventArgs e)
 {
     Thread.Sleep(1000);
     if (WarehouseDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if (WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[8].Value != null &&
                 WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[9].Value == null &&
                 WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[7].Value.ToString() == Status.EntryAllowed)
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         rq.FWHDATEEND = DateTime.Now;
                         rq.FSTATUS    = Status.ShipmentCompleted;
                     }
                     var io = db.InOut.Where(x => x.FID == id)
                              .Where(x => x.FFACTDATEEND == null)
                              .FirstOrDefault();
                     if (io != null)
                     {
                         io.FWHDATEEND = DateTime.Now;
                     }
                     db.SaveChanges();
                 }
                 FillWarehouse();
             }
         }
     }
 }
 private void InButton_Click(object sender, EventArgs e)
 {
     Thread.Sleep(1000);
     if (WarehouseDGV.SelectedRows.Count != 0)
     {
         if (Int32.TryParse(WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[0].Value.ToString(), out int id))
         {
             if (WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[12].Value == null)
             {
                 MessageBox.Show("Нет комментария склада!", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
             if (WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[8].Value == null &&
                 WarehouseDGV.Rows[WarehouseDGV.SelectedRows[0].Index].Cells[7].Value.ToString() == Status.ActiveInput)
             {
                 using (CheckPoint db = new CheckPoint())
                 {
                     var rq = db.Request.Where(x => x.FID == id).FirstOrDefault();
                     if (rq != null)
                     {
                         rq.FWHDATEBEGIN = DateTime.Now;
                         rq.FWHDATEEND   = null;
                         rq.FSTATUS      = Status.EntryAllowed;
                     }
                     var io = db.InOut.Where(x => x.FID == id)
                              .Where(x => x.FFACTDATEEND == null)
                              .FirstOrDefault();
                     if (io != null)
                     {
                         io.FWHDATEBEGIN = DateTime.Now;;
                         io.FWHDATEEND   = null;
                     }
                     db.SaveChanges();
                 }
                 FillWarehouse();
             }
         }
     }
 }
        private void CreateButton_Click(object sender, EventArgs e)
        {
            if (GuestFIOTB.Text == "" || GuestJobTB.Text == "" || LocationTB.Text == "" || PurposeTB.Text == "" || MeetFIOTB.Text == "" || PhoneTB.Text == "")
            {
                MessageBox.Show("Заполнены не все поля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DateTime beginDT = BeginDateDTP.Value.Date.Add(BeginTimeDTP.Value.TimeOfDay);
            DateTime endDT   = EndDateDTP.Value.Date.Add(EndTimeDTP.Value.TimeOfDay);
            DateTime outDT   = OutDateDTP.Value.Date.Add(OutTimeDTP.Value.TimeOfDay);

            if (beginDT.CompareTo(endDT) >= 0)
            {
                MessageBox.Show("Время окончания должно быть больше времени начала!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            using (CheckPoint db = new CheckPoint())
            {
                if (CreateButton.Text == "Создать")
                {
                    if (beginDT.CompareTo(DateTime.Now) < 0)
                    {
                        MessageBox.Show("Время начала должны быть больше текущего!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Request rq = new Request
                    {
                        FCREATEDATE = DateTime.Now,
                        FDESCR      = SystemInformation.UserName,
                        FGUESTFIO   = GuestFIOTB.Text,
                        FGUESTJOB   = GuestJobTB.Text,
                        FAUTOMARK   = AutoMarkTB.Text,
                        FAUTONUMBER = AutoNumberTB.Text,
                        FLOCATION   = LocationTB.Text,
                        FPURPOSE    = PurposeTB.Text,
                        FDATEBEGIN  = beginDT,
                        FDATEEND    = endDT,
                        FMEETFIO    = MeetFIOTB.Text,
                        FPHONE      = PhoneTB.Text,
                        FSTATUS     = Status.Initial
                    };
                    db.Request.Add(rq);
                }
                if (CreateButton.Text == "Изменить")
                {
                    if (beginDT.CompareTo(DateTime.Now) < 0)
                    {
                        MessageBox.Show("Время начала должны быть больше текущего!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var rq = db.Request.Where(x => x.FID == request_id).FirstOrDefault();
                    if (rq != null)
                    {
                        rq.FGUESTFIO   = GuestFIOTB.Text;
                        rq.FGUESTJOB   = GuestJobTB.Text;
                        rq.FAUTOMARK   = AutoMarkTB.Text;
                        rq.FAUTONUMBER = AutoNumberTB.Text;
                        rq.FLOCATION   = LocationTB.Text;
                        rq.FPURPOSE    = PurposeTB.Text;
                        rq.FDATEBEGIN  = beginDT;
                        rq.FDATEEND    = endDT;
                        rq.FMEETFIO    = MeetFIOTB.Text;
                        rq.FPHONE      = PhoneTB.Text;
                        rq.FSTATUS     = Status.Changed;
                    }
                }
                if (CreateButton.Text == "Правка")
                {
                    if (outDT.CompareTo(DateTime.Now) > 0)
                    {
                        MessageBox.Show("Время выхода должно быть меньше текущего!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var rq = db.Request.Where(x => x.FID == request_id).FirstOrDefault();
                    if (rq != null)
                    {
                        rq.FGUESTFIO   = GuestFIOTB.Text;
                        rq.FGUESTJOB   = GuestJobTB.Text;
                        rq.FAUTOMARK   = AutoMarkTB.Text;
                        rq.FAUTONUMBER = AutoNumberTB.Text;
                        rq.FLOCATION   = LocationTB.Text;
                        if (PurposeTB.Text.IndexOf("изменено") != -1)
                        {
                            rq.FPURPOSE = PurposeTB.Text.Substring(0, PurposeTB.Text.IndexOf("изменено")).Trim();
                        }
                        else
                        {
                            rq.FPURPOSE = PurposeTB.Text;
                        }
                        rq.FPURPOSE  += Environment.NewLine + "изменено " + SystemInformation.UserName + " " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
                        rq.FDATEBEGIN = beginDT;
                        rq.FDATEEND   = endDT;
                        rq.FMEETFIO   = MeetFIOTB.Text;
                        rq.FPHONE     = PhoneTB.Text;
                        if (rq.FFACTDATEEND != null)
                        {
                            rq.FFACTDATEEND = outDT;
                        }
                    }
                    var io = db.InOut.Where(x => x.FID == request_id)
                             .OrderByDescending(x => x.FFACTDATEEND)
                             .FirstOrDefault();
                    if (io != null && rq.FFACTDATEEND != null)
                    {
                        io.FFACTDATEEND = outDT;
                    }
                }
                if (CreateButton.Text == "Редактирование")
                {
                    var rq = db.Request.Where(x => x.FID == request_id).FirstOrDefault();
                    if (rq != null)
                    {
                        rq.FWHCOMMENT = WHTB.Text;
                        rq.FWHPERSON  = SystemInformation.UserName;
                    }
                }
                try
                {
                    db.SaveChanges();
                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка обращения к данным!\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }