Exemple #1
0
        private GasStation GetSelectedGasStation()
        {
            int rowNum = GetRowNumFromGSID();

            if (rowNum == -1)
            {
                return(null);
            }
            GasStation GS = new GasStation(selectedGSID, dgvGS.Rows[rowNum].Cells[1].Value.ToString(), dgvGS.Rows[rowNum].Cells[2].Value.ToString());

            List <GasDeliver> GDList    = new List <GasDeliver>();
            List <object[]>   tmpGDList = GlobalConnection.ExecReaderToList("select * from gas_deliver where gas_deliver.gas_station_id = " + selectedGSID);

            for (int i = 0; i < tmpGDList.Count; i++)
            {
                GDList.Add(new GasDeliver(Convert.ToInt32(tmpGDList[i][0]), tmpGDList[i][1].ToString())); // 0 - id, 1 - type, 2 - gas_station_id
            }

            GS.GasDeliverys = GDList;
            //GS.Employees = employeeList;

            return(GS);
        }
Exemple #2
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            //List<Car> cars = new List<Car>();
            //cars.Add(new Car(1));
            //cars.Add(new Car(2));
            //cars.Add(new Car(3));
            //List<Car> tmp = cars.Where(car => car.LeaveTime != DateTime.MinValue).ToList();
            //Car res = tmp.Find(car => car.LeaveTime == tmp.Min(c => c.LeaveTime));
            ////Car cc = cars.Find(c => c.LeaveTime == cars.Min(car => car.LeaveTime));

            //dgvServicing.Rows.Add();
            SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

            builder.IntegratedSecurity = true;
            builder.DataSource         = "localhost";
            builder.InitialCatalog     = "AZS";
            GlobalConnection.SetSQLConnection(new SqlConnection(builder.ConnectionString));
            GlobalConnection.Connection.Open();

            SqlCommand cmd = new SqlCommand("delete from servicing where car_leave_time is null", GlobalConnection.Connection);

            cmd.ExecuteNonQuery();

            try
            {
                //get id from file
                int gsID;
                using (StreamReader sr = new StreamReader("Help.txt"))
                {
                    gsID = Convert.ToInt32(sr.ReadLine().Split('=')[1]);
                }

                // create gas station (select)
                string loc      = "";
                string brand    = "";
                string selectGS = "select * from gas_station where id = " + gsID;
                GlobalConnection.ExecReader(selectGS);
                if (GlobalConnection.Reader.HasRows)
                {
                    for (int i = 0; GlobalConnection.Reader.Read(); i++)
                    {
                        loc   = GlobalConnection.Reader.GetValue(1).ToString();
                        brand = GlobalConnection.Reader.GetValue(2).ToString();
                    }
                }
                GlobalConnection.CloseReader();
                GasStation = new GasStation(gsID, loc, brand);
                List <GasDeliver> GDList    = new List <GasDeliver>();
                List <object[]>   tmpGDList = GlobalConnection.ExecReaderToList("select * from gas_deliver where gas_deliver.gas_station_id = " + gsID);
                for (int i = 0; i < tmpGDList.Count; i++)
                {
                    GDList.Add(new GasDeliver(Convert.ToInt32(tmpGDList[i][0]), tmpGDList[i][1].ToString())); // 0 - id, 1 - type, 2 - gas_station_id
                }
                GasStation.GasDeliverys = GDList;

                GasStationSelectedEvent();

                RefreshDgvServicing();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }