private void btnSave_Click(object sender, EventArgs e)
        {
            int      nTripID  = 0;
            int      nByOrder = 0;
            DateTime?dtDate   = null;
            int      nUserID  = ((RFMFormMain)Application.OpenForms[0]).UserID;

            RFMBindingSource bs = grdTrips.GridSource;
            DataRowView      drv;

            bs.MoveFirst();
            for (int i = 0; i < bs.Count; i++)
            {
                drv = (DataRowView)bs.Current;

                nTripID = (int)drv["ID"];
                dtDate  = null;

                oTrip.ClearError();
                // можно проверить, что рейс не начат, машина не выехала, машина не приехала, рейс не подтвержден и т.д.
                // ...

                // время выхода
                if (!Convert.IsDBNull(drv["DateBegPlan"]))
                {
                    dtDate = Convert.ToDateTime(drv["DateBegPlan"]);

                    /*if (((DateTime)dtDate).Hour == 0 && ((DateTime)dtDate).Minute == 0)
                     *      dtDate = null;*/
                }
                oTrip.SetDateTime(nTripID, "BEG", "PLAN", null, nUserID);
                oTrip.SetDateTime(nTripID, "BEG", "PLAN", dtDate, nUserID);

                // ByOrder
                nByOrder = (int)drv["ByOrder"];

                /*if (!dtDate.HasValue)
                 *      nByOrder = 0;*/
                if ((int)drv["PreByOrder"] != nByOrder)
                {
                    oTrip.SaveByOrder(nTripID, (int)drv["ByOrder"]);
                }

                bs.MoveNext();
            }
            if (oTrip.ErrorNumber == 0)
            {
                DialogResult = DialogResult.Yes;
                Dispose();
            }
        }
Esempio n. 2
0
        private void ChangeMarkedCells(int rankMode, int rankValue)
        {
            dgvCells.IsRestoring = true;

            RFMBindingSource bs = dgvCells.GridSource;
            int    bsIndex      = bs.Position;
            string bsFilter     = bs.Filter;
            string sortExpres   = bs.Sort;

            bs.RemoveSort();
            bs.Filter = "IsMarked";
            bs.MoveFirst();
            DataRowView drv;

            for (int i = 0; i < bs.Count; i++)
            {
                drv = (DataRowView)bs.Current;
                switch (rankMode)
                {
                case 0:
                case 1:
                case 2:
                    drv["Rank"] = rankValue;
                    break;

                case 3:
                case 4:
                    drv["Rank"] = ((int)drv["Rank"]) + rankValue;
                    break;

                default:
                    break;
                }
                bs.MoveNext();
            }
            bs.Filter   = bsFilter;
            bs.Position = bsIndex;
            dgvCells.Invalidate();

            if (!String.IsNullOrEmpty(sortExpres))
            {
                bs.Sort = sortExpres;
            }

            if (chkClearMarkers.Checked)
            {
                dgvCells.MarkAllRows(false);
            }

            dgvCells.IsRestoring = false;
        }
        private void UpdateGroupIndex(ref RFMBindingSource bs, string strFilter, int startIndex)
        {
            startIndex--;
            bs.Filter = strFilter;

            if (bs.Sort.Contains("ByOrder"))
            {
                DataTable dt = (DataTable)bs.DataSource;
                if (!dt.Columns.Contains("ByOrderSort"))
                {
                    dt.Columns.Add("ByOrderSort", Type.GetType("System.Int32"));
                }

                bs.MoveFirst();
                for (int i = 0; i < bs.Count; i++)
                {
                    ((DataRowView)bs.Current)["ByOrderSort"] = i;
                    bs.MoveNext();
                }
                bs.Sort = "ByOrderSort";
            }

            bs.MoveFirst();
            if (bs.Count > 0)
            {
                for (int i = 0; i < bs.Count; i++)
                {
                    startIndex++;
                    ((DataRowView)bs.Current)["ByOrder"] = startIndex;
                    bs.MoveNext();
                }
            }

            bs.Sort = "ByOrder, ID";

            grdTrips.CommitChanges();
        }
        private void btnByTime_Click(object sender, EventArgs e)
        {
            // расставить по времени выезда
            if (RFMMessage.MessageBoxYesNo("Изменить порядок выхода машин в соответствии с указанным планируемым временем выхода?") != DialogResult.Yes)
            {
                return;
            }

            RFMCursorWait.LockWindowUpdate(grdTrips.Handle);

            RFMBindingSource bs = grdTrips.GridSource;

            bs.Sort = "TimeBeg, Alias";

            int         nByOrder = 0;
            string      sTime    = "00:00";
            DataRowView drv;

            bs.MoveFirst();
            for (int i = 0; i < bs.Count; i++)
            {
                drv = (DataRowView)bs.Current;

                /*if (drv["TimeBeg"].ToString().Trim().Length <= 1 || drv["TimeBeg"].ToString() == "00:00")
                 *      nByOrder = 0;
                 * else
                 * {
                 *      //if (sTime != drv["TimeBeg"].ToString().Trim())
                 *      nByOrder++;
                 * }*/
                nByOrder++;
                drv["ByOrder"] = nByOrder;

                sTime = drv["TimeBeg"].ToString().Trim();
                bs.MoveNext();
            }

            grdTrips.Invalidate();

            bs.Sort = "ByOrder";

            SetButtonStatus();

            RFMCursorWait.LockWindowUpdate(IntPtr.Zero);
        }
        private void MoveGroup(bool IsMoveUp)
        {
            RFMBindingSource bs = grdTrips.GridSource;
            int oldIndex        = (int)grdTrips.CurrentRow.Cells["grcByOrder"].Value;

            DataRowView drv;
            int         newIndex;

            if (IsMoveUp)
            {
                newIndex = oldIndex - (int)nudDelta.Value;
                int minIndex = (int)((DataTable)bs.DataSource).Compute("Min(ByOrder)", String.Empty);
                if (newIndex < minIndex)
                {
                    newIndex = minIndex;
                }
            }
            else
            {
                newIndex = oldIndex + (int)nudDelta.Value;
                int maxIndex = (int)((DataTable)bs.DataSource).Compute("Max(ByOrder)", String.Empty);
                if (newIndex > maxIndex)
                {
                    newIndex = maxIndex;
                }
            }

            bs.Filter = "ByOrder = " + oldIndex.ToString();
            bs.MoveFirst();
            for (int i = 0; i < bs.Count; i++)
            {
                ((DataRowView)bs.Current)["IsPickOn"] = true;
                bs.MoveNext();
            }

            if (IsMoveUp)
            {
                bs.Filter = "ByOrder >= " + newIndex.ToString() + " AND ByOrder <= " + oldIndex.ToString();
            }
            else
            {
                bs.Filter = "ByOrder <= " + newIndex.ToString() + " AND ByOrder >= " + oldIndex.ToString();
            }

            bs.Sort = "ID";
            bs.MoveFirst();
            for (int i = 0; i < bs.Count; i++)
            {
                drv = (DataRowView)bs.Current;
                if ((bool)drv["IsPickOn"])
                {
                    drv["ByOrder"]  = newIndex;
                    drv["IsPickOn"] = false;
                }
                else
                {
                    drv["ByOrder"] = (int)drv["ByOrder"] + (IsMoveUp ? 1 : -1);
                }
                bs.MoveNext();
            }
            bs.Sort = "ByOrder, Alias";
            bs.RemoveFilter();

            grdTrips.CommitChanges();
        }