Exemple #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)));
            }
        }
Exemple #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();
        }
Exemple #3
0
 public static void SetSQLConnection(SqlConnection con)
 {
     if (instance == null)
     {
         instance   = new GlobalConnection();
         Connection = con;
     }
 }
Exemple #4
0
 private void dgvGasDeliveriesCellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     GlobalConnection.UpdateGasDeliver(
         dgvGasDeliveries.Rows[e.RowIndex].Cells[1].Value != null ?
         dgvGasDeliveries.Rows[e.RowIndex].Cells[1].Value.ToString() :
         "",
         selectedGSID,
         dgvGasDeliveries.Rows[e.RowIndex].Cells[3].Value != null ?
         Convert.ToInt32(dgvGasDeliveries.Rows[e.RowIndex].Cells[1].Value) :
         -1,
         Convert.ToInt32(dgvGasDeliveries.Rows[e.RowIndex].Cells[0].Value));
 }
Exemple #5
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();
        }
Exemple #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            dgv.Rows.Add(null, textBox1.Text, null);

            GlobalConnection.InsertGasDeliver(
                dgv.Rows[dgv.RowCount - 1].Cells[1].Value != null ? dgv.Rows[dgv.RowCount - 1].Cells[1].Value.ToString() : "",
                GSID);

            SqlCommand cmd = new SqlCommand("select MAX(id) from gas_deliver", GlobalConnection.Connection);
            int        ID  = Convert.ToInt32(cmd.ExecuteScalar());

            dgv.Rows[dgv.RowCount - 1].Cells[0].Value = ID;             // set id

            this.Close();
        }
Exemple #7
0
 private void DgvGS_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     //if (_isInsertNeeded)        // if there is new line added insert new line into database, else update this line
     //{
     //    GlobalConnection.InsertGasStation(
     //        dgvGS.Rows[e.RowIndex].Cells[1].Value != null ? dgvGS.Rows[e.RowIndex].Cells[1].Value.ToString() : "",
     //        dgvGS.Rows[e.RowIndex].Cells[2].Value != null ? dgvGS.Rows[e.RowIndex].Cells[2].Value.ToString() : "");
     //    _isInsertNeeded = false;
     //}
     //else
     //{
     GlobalConnection.UpdateGasStation(
         dgvGS.Rows[e.RowIndex].Cells[1].Value != null ? dgvGS.Rows[e.RowIndex].Cells[1].Value.ToString() : "",
         dgvGS.Rows[e.RowIndex].Cells[2].Value != null ? dgvGS.Rows[e.RowIndex].Cells[2].Value.ToString() : "",
         Convert.ToInt32(dgvGS.Rows[e.RowIndex].Cells[0].Value));
     //}
 }
Exemple #8
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();
        }
Exemple #9
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 #10
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);
            }
        }