Exemplo n.º 1
0
        private void UpdateExsistingOrder(int newQty, int id = 0, string line = "", DateTime date = default(DateTime))
        {
            var jobModel = new JobModel();

            if (line == string.Empty)
            {
                line = _bar.Tag;
            }
            if (date == default(DateTime))
            {
                date = _bar.FromTime;
            }
            var duration  = jobModel.CalculateJobDuration(line, newQty, _bar.QtyH, _bar.Department, _bar.Members);
            var dailyProd = jobModel.CalculateDailyQty(line, _bar.QtyH, _bar.Department, _bar.Members, newQty);

            var durationTick = TimeSpan.FromDays(duration).Ticks;
            var eDate        = date.AddTicks(durationTick);

            var shift = new ShiftRecognition();

            eDate = shift.GetEndTimeInShift(date, eDate);

            //eDate = new DateTime(eDate.Year, eDate.Date.Month, eDate.Day, eDate.Hour, eDate.Minute, 0, 0);

            using (var con = new System.Data.SqlClient.SqlConnection(Central.SpecialConnStr))
            {
                var updateQuery = @"
update objects set loadedQty=@LoadedQty, duration=@Duration, endDate=@EndDate, dailyProd=@DailyProd, closedord=@ClosedOrd
where Id=@Id;";

                var cmd = new System.Data.SqlClient.SqlCommand(updateQuery, con);
                cmd.Parameters.Add("@LoadedQty", SqlDbType.Int).Value  = newQty;
                cmd.Parameters.Add("@Duration", SqlDbType.Float).Value = duration;
                cmd.Parameters.Add("@EndDate", SqlDbType.BigInt).Value = eDate.Ticks;
                cmd.Parameters.Add("@DailyProd", SqlDbType.Int).Value  = dailyProd;
                cmd.Parameters.Add("@Id", SqlDbType.Int).Value         = id == 0 ? _bar.Id : id;

                if (_bar.ProductionQty > 0 && _bar.LoadedQty - _bar.ProductionQty == newQty)
                {
                    cmd.Parameters.Add("@ClosedOrd", SqlDbType.Bit).Value = true;
                }
                else
                {
                    cmd.Parameters.Add("@ClosedOrd", SqlDbType.Bit).Value = false;
                }

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
Exemplo n.º 2
0
        private void InsertFractionatedOrder(int newQty, int newMembers)
        {
            var loadingJob = new LoadingJob(false);

            var jobModel = new JobModel();
            var task     = Central.TaskList.Where(x => x.Id == _bar.Id).FirstOrDefault();

            var duration  = jobModel.CalculateJobDuration(cboLine.Text, newQty, _bar.QtyH, _bar.Department, newMembers);
            var startDate = !Store.Default.manualDate ? JobModel.GetLineNextDate(cboLine.Text, _bar.Department) : dtpStart.Value;

            var dailyProd = jobModel.CalculateDailyQty(cboLine.Text, _bar.QtyH, _bar.Department, newMembers, newQty);

            var newRowText = string.Empty;

            if (_bar.RowText.Contains('_'))
            {
                int.TryParse(_bar.RowText.Split('_')[1], out var newIndex);
                newRowText = _bar.RowText.Split('_')[0] + '_' + (newIndex + 1).ToString();

                var newTask = Central.TaskList.Where(x => x.Name == newRowText && x.Department == _bar.Department).FirstOrDefault();

                if (newTask != null)
                {
                    int.TryParse(newTask.Name.Split('_')[1], out var n);
                    newRowText = _bar.RowText.Split('_')[0] + '_' + (n + 1).ToString();
                }
            }
            else
            {
                newRowText = _bar.RowText + "_1";
            }

            loadingJob.InsertNewProgram(newRowText, cboLine.Text, _bar.Article, newQty,
                                        _bar.QtyH, startDate, duration, dailyProd,
                                        task.ArtPrice, _bar.Department, newMembers, dtpStart.Checked, false);
        }