예제 #1
0
        private void okBtn_Click(object sender, EventArgs e)
        {
            if (rendszamBox.Text.Trim() == "")
            {
                MessageBox.Show("A Rendszám mező nem lehet üres", "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (!Auto.Rendex.IsMatch(rendszamBox.Text))
            {
                MessageBox.Show("A rendszám alakja a következő: 'ABC-123'", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (kapacitas.Value == 0m)
            {
                MessageBox.Show("A kapacitás nem lehet 0", "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (sofor.Text.Trim() == "")
            {
                MessageBox.Show("Adja meg a jármű vezetőjét!", "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            car.Rendszam = rendszamBox.Text.ToUpper();
            car.Sofor    = sofor.Text;
            car.Seged    = seged.Text;

            car.SetNapszakFordulok(0, (int)elsofuvar.Value);
            car.SetNapszakFordulok(1, (int)delelott.Value);
            car.SetNapszakFordulok(2, (int)delutan.Value);

            car.Fogyasztas = (float)uzemanyag.Value;
            car.Lizingdij  = (float)lizing.Value;

            car.Kapacitas = (int)kapacitas.Value;

            DialogResult = DialogResult.OK;
            Close();
        }
예제 #2
0
        void goodcars_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string val = goodcars[e.ColumnIndex, e.RowIndex].Value == null ? "0" : goodcars[e.ColumnIndex, e.RowIndex].Value.ToString();
                int    intVal;
                float  floatVal;

                if (select == null)
                {
                    return;
                }

                switch (e.ColumnIndex)
                {
                case 1:
                    try
                    {
                        intVal = int.Parse(val);

                        if (intVal < 0)
                        {
                            MessageBox.Show("'Tartályméret' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        /*if (select.IsJozsaiAuto && intVal < select.Kapacitas)
                         * {
                         *      MessageBox.Show("A jármű tartálymérete nem csökkenthető, mivel a jármű fel nem szabadítható címeket szolgál ki.", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         *      throw new FormatException();
                         * }*/

                        if (BeforeKapacitasChg != null && !BeforeKapacitasChg(select, intVal))
                        {
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Tartályméret", select.Kapacitas.ToString(), intVal.ToString());

                        select.Kapacitas = intVal;
                    }
                    catch (FormatException)
                    {
                        goodcars[e.ColumnIndex, e.RowIndex].Value = select.Kapacitas;
                    }

                    DoCarUpdate();

                    break;

                case 2:
                    try
                    {
                        intVal = int.Parse(val);

                        if (intVal < 0)
                        {
                            MessageBox.Show("'Első fuvar' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        if (BeforeElsoFuvarChg != null && !BeforeElsoFuvarChg(select, intVal))
                        {
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Első fuvar", select.GetNapszakFordulok(0).ToString(), intVal.ToString());

                        select.SetNapszakFordulok(0, intVal);
                        if (select.IsJozsaiAuto)
                        {
                            goodcars[2, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(0), select.GetNapszakJozsa(0));
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = string.Format("{0} [{1}]", select.OsszFordulo, select.OsszCimJozsa);
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }

                        DoSumma();
                    }
                    catch (FormatException)
                    {
                        if (select.IsJozsaiAuto)
                        {
                            goodcars[2, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(0), select.GetNapszakJozsa(0));
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }
                    }
                    break;

                case 3:
                    try
                    {
                        intVal = int.Parse(val);

                        if (intVal < 0)
                        {
                            MessageBox.Show("'Délelőtt' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        if (BeforeDelelottChg != null && !BeforeDelelottChg(select, intVal))
                        {
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Délelőtt", select.GetNapszakFordulok(1).ToString(), intVal.ToString());

                        select.SetNapszakFordulok(1, intVal);

                        if (select.IsJozsaiAuto)
                        {
                            goodcars[3, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(1), select.GetNapszakJozsa(1));
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = string.Format("{0} [{1}]", select.OsszFordulo, select.OsszCimJozsa);
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }

                        DoSumma();
                    }
                    catch (FormatException)
                    {
                        if (select.IsJozsaiAuto)
                        {
                            goodcars[3, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(1), select.GetNapszakJozsa(1));
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }
                    }
                    break;

                case 4:
                    try
                    {
                        intVal = int.Parse(val);

                        if (intVal < 0)
                        {
                            MessageBox.Show("'Délután' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        if (BeforeDelutanChg != null && !BeforeDelutanChg(select, intVal))
                        {
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Délután", select.GetNapszakFordulok(2).ToString(), intVal.ToString());

                        select.SetNapszakFordulok(2, intVal);

                        if (select.IsJozsaiAuto)
                        {
                            goodcars[4, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(2), select.GetNapszakJozsa(2));
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = string.Format("{0} [{1}]", select.OsszFordulo, select.OsszCimJozsa);
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }

                        DoSumma();
                    }
                    catch (FormatException)
                    {
                        if (select.IsJozsaiAuto)
                        {
                            goodcars[4, e.RowIndex].Value = string.Format("{0} [{1}]", select.GetNapszakFordulok(2), select.GetNapszakJozsa(2));
                        }
                        else
                        {
                            goodcars[Osszfuvar.Index, e.RowIndex].Value = select.OsszFordulo;
                        }
                    }
                    break;

                case 7:
                    try
                    {
                        floatVal = float.Parse(val);

                        if (floatVal < 0)
                        {
                            MessageBox.Show("'Fogyasztás' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Fogyasztás", select.Fogyasztas.ToString(), floatVal.ToString());

                        select.Fogyasztas = floatVal;
                        goodcars[osszkoltseg.Index, e.RowIndex].Value = (select.Lizingdij + select.Ber) / Properties.Settings.Default.workDays;
                    }
                    catch (FormatException)
                    {
                        goodcars[e.ColumnIndex, e.RowIndex].Value = select.Fogyasztas;
                    }
                    break;

                case 8:
                    try
                    {
                        floatVal = float.Parse(val);

                        if (floatVal < 0)
                        {
                            MessageBox.Show("'Lízing' értéke nem lehet negatív", "Hibás érték", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            throw new FormatException();
                        }

                        AppLogger.WriteAutoChange(select.Rendszam, "Lízing", select.Lizingdij.ToString(), floatVal.ToString());

                        select.Lizingdij = floatVal;
                        goodcars[osszkoltseg.Index, e.RowIndex].Value = (select.Lizingdij + select.Ber) / Properties.Settings.Default.workDays;
                        goodcars.CurrentCell.Value = floatVal / Properties.Settings.Default.workDays;
                    }
                    catch (FormatException)
                    {
                        goodcars[e.ColumnIndex, e.RowIndex].Value = select.Lizingdij;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                AppLogger.WriteException(ex);
                AppLogger.WriteEvent("A kivétel elkapva.");
            }
        }
예제 #3
0
        private void RestoreState(string sourceFile)
        {
            Reset();
            fileName = sourceFile;
            List <WorkData> allWork = new List <WorkData>();

            Auto        car;
            XmlDocument sourceDoc = new XmlDocument();
            WorkData    wd;

            int maxVehIndex = 0;

            try
            {
                FileStream fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sourceDoc.Load(fs);

                DateTime sourceDate = DateTime.Parse(sourceDoc.DocumentElement.Attributes["date"].Value);
                dateChooser.Value = sourceDate;

                //Autók
                XmlNode         xmlNode  = sourceDoc.DocumentElement.ChildNodes[0];
                List <WorkData> workList = new List <WorkData>();
                int             dest;

                foreach (XmlNode node in xmlNode.ChildNodes)
                {
                    car = new Auto(node.Attributes[0].Value);

                    car.Kapacitas  = int.Parse(node.Attributes[1].Value);
                    car.Lizingdij  = float.Parse(node.Attributes[8].Value);
                    car.Fogyasztas = float.Parse(node.Attributes[9].Value);

                    car.SetNapszakFordulok(0, int.Parse(node.Attributes[2].Value));
                    car.SetNapszakFordulok(1, int.Parse(node.Attributes[3].Value));
                    car.SetNapszakFordulok(2, int.Parse(node.Attributes[4].Value));

                    car.Index = int.Parse(node.Attributes[5].Value);
                    if (car.Index > maxVehIndex)
                    {
                        maxVehIndex = car.Index;
                    }

                    car.Sofor = node.Attributes[6].Value;
                    car.Seged = node.Attributes[7].Value;



                    //Fordulók

                    foreach (XmlNode groupNode in node.ChildNodes)
                    {
                        workList.Clear();
                        dest = int.Parse(groupNode.Attributes[0].Value);
                        foreach (XmlNode workNode in groupNode.ChildNodes)
                        {
                            wd = new WorkData();
                            wd.ParseFromXml(workNode);

                            wd.ParseFold(workNode);
                            wd.ParseKoord(workNode);

                            summary.UpdateWith(wd);

                            workList.Add(wd);
                            allWork.Add(wd);
                        }

                        car.AddFuvar(workList, dest);
                    }

                    vehicles.Add(car);
                }

                if (!Properties.Settings.Default.mentettAuto)
                {
                    dao.GetAutoAdat(vehicles);
                }

                Auto.AutoIndex = maxVehIndex + 1;

                //Csórikák
                xmlNode = sourceDoc.DocumentElement.ChildNodes[1];

                foreach (XmlNode cimNode in xmlNode.ChildNodes)
                {
                    wd = new WorkData();
                    wd.ParseFromXml(cimNode);

                    wd.ParseFold(cimNode);
                    wd.ParseKoord(cimNode);

                    summary.UpdateWith(wd);
                    allWork.Add(wd);

                    if (wd.WorkCapacity <= WorkData.BigCapacityLimit)
                    {
                        if (!wd.Jozsai)
                        {
                            unfive[wd.Napszak - 1]++;
                            m3small[0] += wd.WorkCapacity;
                        }
                        else
                        {
                            unfive[wd.Napszak + 2]++;
                            m3small[1] += wd.WorkCapacity;
                        }
                    }
                    else
                    {
                        if (!wd.Jozsai)
                        {
                            unbig[wd.Napszak - 1]++;
                            m3big[0] += wd.WorkCapacity;
                        }
                        else
                        {
                            unbig[wd.Napszak + 2]++;
                            m3big[1] += wd.WorkCapacity;
                        }
                    }
                }

                if (!Properties.Settings.Default.mentettFold)
                {
                    dao.GetFoldLatLng(allWork);
                }
                if (!Properties.Settings.Default.mentettKoord)
                {
                    dao.GetLatLng(allWork);
                }

                Properties.Settings.Default.lastDir = sourceFile.Substring(0, sourceFile.LastIndexOf('\\'));
                LoadMarkersFromData(allWork);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Állomány megnyitása sikertelen.\nEz a verzió valószínűleg nem kompatibilis a régebbi mentésekkel.",
                                "Megnyitás sikertelen", MessageBoxButtons.OK, MessageBoxIcon.Error);

                AppLogger.WriteException(ex);
                AppLogger.WriteEvent("A kivétel elkapva.");
                Reset();
            }

            AppLogger.WriteOpen(fileName);
        }