private void ButtonPrem_Click object sender EventArgs int Int32 Parse

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
private void ButtonPrem_Click(object sender, EventArgs e)
{
int x = Int32.Parse(iD_EmployeeTextBox1.Text);
string sqlSelect = "";
if (String.IsNullOrEmpty(iD_EmployeeTextBox1.Text))
{
MessageBox.Show("Обязательно укажите ID необходимого сотрудника.", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}//DATEADD(ms, SUM(DATEDIFF(ms, '00:00:00.000', C.Duration_service)), '00:00:00.000') as tim
else if (!empty)
{
label3.Visible = true;
textBoxDte.Visible = true;
label1.Visible = true;
textBox1.Visible = true;
label2.Visible = true;
SqlConnection connection = new SqlConnection(Properties.Settings.Default.beauty_saloon_MarigoldConnectionString);
connection.Open();
SqlCommand command = connection.CreateCommand();
if (radioButton1.Checked)
{
DateTime newdate = new DateTime();
newdate = DateTime.Now.AddDays(-30);
sqlSelect = @"Select CONVERT(TIME, DATEADD(s, SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)), '00:00:00.000')) AS tim,
(SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)))/(24*3600) AS dte
FROM Timetable A , Employees B, [Services] C
Where A.ID_Employee = B.ID_Employee AND
A.ID_Service = C.ID_Service AND
A.Service_done = 'да' AND
A.ID_Employee = @ID AND
A.[Date] >= @TME";
command.CommandText = sqlSelect;
command.Parameters.AddWithValue("@ID", x);
command.Parameters.AddWithValue("@TME", newdate);
}
else if (radioButton3.Checked)
{
DateTime newdate = new DateTime();
newdate = dateTimePicker1.Value;
sqlSelect = @"Select CONVERT(TIME, DATEADD(s, SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)), '00:00:00.000')) AS tim,
(SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)))/(24*3600) AS dte
FROM Timetable A , Employees B, [Services] C
Where A.ID_Employee = B.ID_Employee AND
A.ID_Service = C.ID_Service AND
A.Service_done = 'да' AND
A.ID_Employee = @ID AND
A.[Date] >= @TME";
command.CommandText = sqlSelect;
command.Parameters.AddWithValue("@ID", x);
command.Parameters.AddWithValue("@TME", newdate);
}
else
{
sqlSelect = @"Select CONVERT(TIME, DATEADD(s, SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)), '00:00:00.000')) AS tim,
(SUM((DATEPART(hh, C.Duration_service)*3600)+(DATEPART(mi, C.Duration_service)*60)+DATEPART(ss, C.Duration_service)))/(24*3600) AS dte
FROM Timetable A , Employees B, [Services] C
Where A.ID_Employee = B.ID_Employee AND
A.ID_Service = C.ID_Service AND
A.Service_done = 'да' AND
A.ID_Employee = @ID";
command.CommandText = sqlSelect;
command.Parameters.AddWithValue("@ID", x);
}
SqlDataReader reader = command.ExecuteReader();
reader.Read();
string stk;
stk = reader["tim"].ToString(); //часы отработанные сотрудником
if (String.IsNullOrEmpty(stk))
{
MessageBox.Show("Сотрудник еще не работал11!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Clear();
textBoxDte.Clear();
}
else
{
textBox1.Text = stk;
stk = reader["dte"].ToString(); //дни отработанные сотрудником
textBoxDte.Text = stk;
string tst = Convert.ToString(textBox1.Text[0]) + Convert.ToString(textBox1.Text[1]);//не нужно
test.Text = tst;//не нужно
double tst1;
int lenght = standard_salaryTextBox1.Text.Length - 1;
tst1 = Convert.ToDouble(textBoxDte.Text);
if (tst1 == 0)
{
tst1 = double.Parse(textBox1.Text[0].ToString()); //Convert.ToDouble(textBox1.Text[1]);
test.Text = Convert.ToString(tst1);
if (tst1 == 0)
{
premium_sizeTextBox1.Text = "0";
}
else
{
tst1 = double.Parse(Convert.ToString(textBox1.Text[0]) + Convert.ToString(textBox1.Text[1]));
premium_sizeTextBox1.Text = Convert.ToString(Math.Round((Convert.ToDouble(tst1) / 4800) * (Convert.ToDouble(standard_salaryTextBox1.Text.Remove(lenght))), 1));
}
}
else
{
double PREMIA;
tst1 = Convert.ToDouble(textBoxDte.Text);
PREMIA = (Convert.ToDouble(tst1) / 200) * (Convert.ToDouble(standard_salaryTextBox1.Text.Remove(lenght)));
premium_sizeTextBox1.Text = Convert.ToString(PREMIA);
}
}
}
else
{
MessageBox.Show("Сотрудник еще не работал!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
premium_sizeTextBox1.Focus();
}