Esempio n. 1
0
        private void FormManageGS_Load(object sender, EventArgs e)
        {
            SetDgvGSColumns();
            SetDgvGasDeliverColumns();
            //SetDgvStaffColumns();

            string selectGS = "select * from gas_station";

            GlobalConnection.ExecReader(selectGS);
            FillDGVFromReader(dgvGS);
            GlobalConnection.CloseReader();

            dgvGS.RowHeaderMouseDoubleClick += DgvGS_RowHeaderMouseDoubleClick;
            dgvGS.CellEndEdit += DgvGS_CellEndEdit;

            dgvGasDeliveries.CellEndEdit += dgvGasDeliveriesCellEndEdit;

            //dgvStaff.CellEndEdit += dgvStaffCellEndEdit;



            if (GasStation != null) // if GasStation was selected earlie imitate selection by double click
            {
                int rowNum = 0;
                for (int i = 0; i < dgvGS.Rows.Count; i++)
                {
                    if (Convert.ToInt32(dgvGS.Rows[i].Cells[0].Value) == GasStation.ID)
                    {
                        rowNum = i;
                        break;
                    }
                }
                DgvGS_RowHeaderMouseDoubleClick(dgvGS, new DataGridViewCellMouseEventArgs(-1, rowNum, 0, 0, new MouseEventArgs(MouseButtons.Left, 2, 0, 0, 0)));
            }
        }
Esempio n. 2
0
        private void RefreshDgvServicing()
        {
            // select all servicing with cars only from selected GS
            GlobalConnection.ExecReader("select * from servicing where gas_deliver_id in (select id from gas_deliver where gas_station_id = " + GasStation.ID + ")");

            dgvServicing.Columns.Clear();
            dgvServicing.Refresh();
            for (int j = 0; j < GlobalConnection.Reader.FieldCount; j++)
            {
                dgvServicing.Columns.Add(GlobalConnection.Reader.GetName(j), GlobalConnection.Reader.GetName(j));
            }
            dgvServicing.Columns[3].Width = 150;        // columns for data must be wider
            dgvServicing.Columns[4].Width = 150;
            if (GlobalConnection.Reader.HasRows)
            {
                for (int i = 0; GlobalConnection.Reader.Read(); i++)
                {
                    dgvServicing.Rows.Add();
                    for (int j = 0; j < GlobalConnection.Reader.FieldCount; j++)
                    {
                        dgvServicing.Rows[i].Cells[j].Value = GlobalConnection.Reader[j];
                    }
                }
            }

            GlobalConnection.Reader.Close();
        }
Esempio n. 3
0
        private void SelectGS(int rowInd)
        {
            string GSid = dgvGS.Rows[rowInd].Cells[0].Value.ToString();
            string selectGasDelivers = "select * from gas_deliver where gas_deliver.gas_station_id = " + GSid;

            GlobalConnection.ExecReader(selectGasDelivers);
            FillDGVFromReader(dgvGasDeliveries);
            GlobalConnection.CloseReader();

            selectedGSID = Convert.ToInt32(GSid);
            HighlightSelectedGS();
        }
Esempio n. 4
0
        private void FormShowServicing_Load(object sender, EventArgs e)
        {
            GlobalConnection.ExecReader("select * from servicing where gas_deliver_id in (select id from gas_deliver where gas_station_id = " + GS.ID + ")");

            for (int j = 0; j < GlobalConnection.Reader.FieldCount; j++)
            {
                dgvServicing.Columns.Add(GlobalConnection.Reader.GetName(j), GlobalConnection.Reader.GetName(j));
            }
            if (GlobalConnection.Reader.HasRows)
            {
                for (int i = 0; GlobalConnection.Reader.Read(); i++)
                {
                    dgvServicing.Rows.Add();
                    for (int j = 0; j < GlobalConnection.Reader.FieldCount; j++)
                    {
                        dgvServicing.Rows[i].Cells[j].Value = GlobalConnection.Reader[j];
                    }
                }
            }

            GlobalConnection.Reader.Close();
        }
Esempio n. 5
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);
            }
        }