Пример #1
0
        private void btnPost_Click(object sender, EventArgs e)
        {
            string date = this.dtmShiftStart.Text.ToString();

            //string starttime = this.mtxtStartTime.Text.ToString();
            //string stoptime = this.mtxtStopTime.Text.ToString();

            string starttime = dtStart.Value.ToString();
            string stoptime  = dtStop.Value.ToString();


            DateTime dts  = DateTime.Parse(starttime);
            DateTime dtss = DateTime.Parse(stoptime);



            DateTime dtvstart = Convert.ToDateTime(date + " " + dts.TimeOfDay);
            DateTime dtvstop  = Convert.ToDateTime(date + " " + dtss.TimeOfDay);

            TimeSpan hrbooked = dtss - dts;
            //DateTime dtStartTimeValue = dtStart.Text;

            var just_date = dtvstart.Date;
            //DateTime dt1start = DateTime.ParseExact(date + " " + starttime, "M/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture);
            var timecheck = from mu in context.mill_Mills_Utilization
                            where cmbMill.Text == mu.Mill_ID && dtStart.Value <mu.Shift_Stop_Time && dtStop.Value> mu.Shift_Start_Time
                            select new { mu.Mills_Utilization_ID, mu.Mill_ID, mu.Shift_Start_Time, mu.Shift_Stop_Time };

            if (timecheck.Count() == 0)
            {
                if (dtStart.Value <= dtStop.Value)
                {
                    if (hrbooked.TotalHours <= 24)
                    {
                        if (cmbCategory.SelectedItem != null)
                        {
                            using (Model1 record = new Model1())
                            {
                                mill_Mills_Utilization rec = new mill_Mills_Utilization();
                                {
                                    rec.Mill_ID          = cmbMill.Text;
                                    rec.gl_cmp_key       = cmbCompany.Text;
                                    rec.sf_plant_key     = cmbPlant.Text;
                                    rec.Start_Time       = dts;
                                    rec.Stop_Time        = dtss;
                                    rec.Memo             = rtxtMemo.Text;
                                    rec.System           = cmbSystem.Text;
                                    rec.Shift            = cmbShift.Text;
                                    rec.Shift_Category   = cmbCategory.Text;
                                    rec.Run_Code         = cmbRunCode.Text;
                                    rec.Shift_Start_Date = dtStart.Value;
                                    rec.Shift_Start_Time = dtvstart;
                                    rec.Shift_Stop_Time  = dtvstop;
                                    rec.Mill_temp        = Decimal.Parse(mtxtTemp.Text);
                                    rec.D10         = Decimal.Parse(mtxtD10.Text);
                                    rec.D50         = Decimal.Parse(mtxtD50.Text);
                                    rec.D90         = Decimal.Parse(mtxtD90.Text);
                                    rec.D98         = Decimal.Parse(mtxtD98.Text);
                                    rec.Item_Number = txtItemNo.Text;

                                    rec.Mill_Hours_Booked = hrbooked;
                                    rec.SO_Number         = Int32.Parse(txtSONumber.Text);
                                    rec.sa_user_key       = Program.GetUser();
                                    rec.Created_by        = Program.GetUser();
                                    rec.Created_date      = DateTime.Now;

                                    record.mill_Mills_Utilization.Add(rec);
                                    record.SaveChanges();

                                    context.mill_Mills_Utilization.ToList();


                                    string company = cmbCompany.Text;
                                    string plant   = cmbPlant.Text;

                                    var query = from mu in context.mill_Mills_Utilization
                                                orderby mu.Mills_Utilization_ID descending
                                                where mu.gl_cmp_key == company && mu.sf_plant_key == plant
                                                select mu;

                                    bs.DataSource          = query.ToList();
                                    dgvMillUtil.DataSource = bs;
                                }
                            }
                        }
                        else
                        {
                            ttCategory.Show("Category cannot be blank.  Please Pick a Category", cmbCategory, 0, 25);
                        }
                    }

                    else
                    {
                        tt24.Show("Time Span cannot be greater then 24 hours. Please check start and top time", dtStop, 0, 25);
                    }
                }

                else
                {
                    ttTime.Show("Start time cannot be greater then Stop Time", dtStart, 0, 25);
                }
            }
            else
            {
                ttDuplicateMillShift.Show("Shift for this Mill already exisits, please change time or mill", btnPost, 0, 25);
            }
        }