Torna al Thread
DateTime dataCorrente;
private void createButton(DateTime _inizio,String _durata)
{
DateTime init = _inizio;
String dur = _durata;
bool sent = false;
// init=init.ToString().Substring(10, 6).Trim();
int durataInQuarti = Convert.ToInt16(dur)/15;
monthCalendar1.Visible = false;
string[] ore = new string[48];
System.Windows.Forms.Button[] Buttons =
new System.Windows.Forms.Button[48];
double i, t;
for (i = 0; i < 24; ++i)
for (t = 0; t <= 45; t = t+15)
{
Buttons[(int)i] = new Button();
if (t.ToString().Length == 1)
Buttons[(int)i].Text = (i.ToString() + "." + t.ToString().Trim() + "0");
else Buttons[(int)i].Text = i.ToString() + "." + t.ToString().Trim();
for(int z=0;z<95;z++)
if (Buttons[(int)i].Text.Equals(init)||sent==true)
{
Buttons[(int)i].Enabled = false;
durataInQuarti--;
if(durataInQuarti!=0) sent=true;
else sent=false;
}
Buttons[(int)i].Location = new System.Drawing.Point(
15 + (int)i * 50, 15 + (int)t * 5);
Buttons[(int)i].Size = new System.Drawing.Size(50, 50);
Buttons[(int)i].Tag = init;
groupBox1.Controls.Add(Buttons[(int)i]);
this.Controls.Add(groupBox1);
}
}
private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
{
String dC = e.Start.ToShortDateString();
dataCorrente = Convert.ToDateTime(dC);
try
{
MySql.Data.MySqlClient.MySqlDataAdapter da = new MySql.Data.MySqlClient.MySqlDataAdapter();
DataTable tabella = new DataTable();
da.SelectCommand = new MySql.Data.MySqlClient.MySqlCommand();
da.SelectCommand.Connection = new MySqlConnection(global::drill_manager.Properties.Settings.Default.gestione_impiantoConnectionString);
da.SelectCommand.CommandType = CommandType.Text;
da.SelectCommand.CommandText = "SELECT inizio,durata FROM prenotazione WHERE DATE(inizio)= ?inizio;";
da.SelectCommand.Parameters.Add("?inizio", MySql.Data.MySqlClient.MySqlDbType.DateTime).Value = dataCorrente;
if (da.SelectCommand.Connection.State == ConnectionState.Closed)
{
da.SelectCommand.Connection.Open();
}
da.Fill(tabella);
if (tabella.Rows.Count > 0)
{
for (int i = 0; i <= tabella.Rows.Count - 1; i++)
{
// MessageBox.Show(tabella.Rows[i]["inizio"].ToString());
//MessageBox.Show(tabella.Rows[i]["inizio"].ToString());
createButton(Convert.ToDateTime(tabella.Rows[i]["inizio"]), tabella.Rows[i]["durata"].ToString());
}
}
else MessageBox.Show("Nessun record");
}
catch (MySqlException me)
{ }
}