private void dtGridProjects_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex >= 0) { dtGridProjects.Rows[e.RowIndex].Selected = true; } int id = Convert.ToInt32(dtGridProjects.Rows[e.RowIndex].Cells[0].Value); string projectname = dtGridProjects.Rows[e.RowIndex].Cells[1].Value.ToString(); if (dtGridProjects.Rows[e.RowIndex].Selected) { frmListOfMainProcess lomp = new frmListOfMainProcess(id, projectname, UsersID); lomp.Show(); } }
private void btnSave_Click(object sender, EventArgs e) { string ProcessName = txtProcessName.Text; DateTime StartDate = Convert.ToDateTime(dtpStartDate.Text); DateTime FinishDate = Convert.ToDateTime(dtpFinishDate.Text); int Duration = Convert.ToInt32(txtDuration.Text); int Priority = Convert.ToInt32(cmbPriority.Text); string Notes = txtNotes.Text; string Descriptions = txtDescription.Text; int CompleteRate = Convert.ToInt32(cmbCompleteRate.Text); string WorkFollowName = txtWorkFollowName.Text; string FromWho = cmbFromWho.Text; TimeSpan gunFarki = dtpFinishDate.Value.Subtract(dtpStartDate.Value); int fark = Convert.ToInt32(gunFarki.Days); if (fark <= 0) { MessageBox.Show("Please enter finish date bigger than start date."); dtpFinishDate.Focus(); } else { string connectionString = @"Data Source=TOSHIBA;Integrated Security=True;Initial Catalog=YazilimYonetimAraci;"; SqlConnection con = new SqlConnection(connectionString); con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM tblUsers WHERE UsersID = @UsersID", con); cmd.Parameters.AddWithValue("UsersID", UsersID); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { Users u = new Users(); while (reader.Read() == true) { u.UsersID = Convert.ToInt32(reader[0]); } int UsersID = u.UsersID; int ProjectID = id; ParentID = 1; ProcessID += 1; reader.Close(); cmd.CommandText = "INSERT INTO tblProcess (ProcessName,ProjectID, StartDate, FinishDate,Duration,CompleteRate,Priority,ParentID,Notes,Descriptions,CreateUserID) VALUES(@ProcessName, @ProjectID, @StartDate,@FinishDate ,@Duration, @CompleteRate,@Priority, @ParentID,@Notes,@Descriptions,@UsersID)"; cmd.Parameters.AddWithValue("@ProcessName", ProcessName); cmd.Parameters.AddWithValue("@ProjectID", ProjectID); cmd.Parameters.AddWithValue("@StartDate", StartDate); cmd.Parameters.AddWithValue("@FinishDate", FinishDate); cmd.Parameters.AddWithValue("@Duration", Duration); cmd.Parameters.AddWithValue("@CompleteRate", CompleteRate); cmd.Parameters.AddWithValue("@Priority", Priority); cmd.Parameters.AddWithValue("@ParentID", ParentID); cmd.Parameters.AddWithValue("@Notes", Notes); cmd.Parameters.AddWithValue("@Descriptions", Descriptions); cmd.Parameters.AddWithValue("@CreateUserID", UsersID); cmd.ExecuteNonQuery(); con.Close(); con.Open(); cmd.CommandText = "INSERT INTO tblWorkFollowDetails (WorkFollowName) VALUES (@WorkFollowName)"; cmd.Parameters.AddWithValue("@WorkFollowName", WorkFollowName); cmd.ExecuteNonQuery(); con.Close(); Insert(); MessageBox.Show("The process was saved."); } con.Close(); this.Close(); frmListOfMainProcess lomp = new frmListOfMainProcess(id, projectName, UsersID); //lomp.Show(); } }