public void loadAppropriateWindow() { try { SqlConnection con = Database.GetConnectionObj(); if (con == null) throw new Exception("Can't create and open a connection"); SqlCommand cmd = new SqlCommand("", con); cmd.CommandText = string.Format( "SELECT file_name FROM dbo.file_list WHERE solver_name = '{0}' AND solve_status = 'solving'", username); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { string filename = reader[0].ToString(); //SolveWindow slw = new SolveWindow(filename, username, getSub(filename), this, false); //this.Hide(); //slw.Show(); E_solve slw = new E_solve(filename, username, getSub(filename), this, false); this.Hide(); slw.Show(); //this.Close(); } else { File_List file_list_form = new File_List(username,this); file_list_form.Show(); this.Hide(); } reader.Dispose(); con.Close(); con.Dispose(); } catch (Exception ee) { MessageBox.Show("Database error.\n" + ee.StackTrace.ToString()); Application.Exit(); } }
private void relese() { //throw new NotImplementedException(); if (MessageBox.Show("Are you really want to RELESE this file?\n" + "All Corrections made will be lost." + "Press 'Yes' to RELESE this file.\n" + "Press 'No' to return to solving window.\n", "Finish Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { SqlConnection con = Database.GetConnectionObj(); if (con == null) throw new Exception("Can't create and open a connection"); SqlCommand cmd = new SqlCommand("", con); cmd.CommandText = string.Format( "UPDATE dbo.file_list " + "SET solver_name = '__NONE', solver_comments = solver_comments +' {0} Relesed on ' + CURRENT_TIMESTAMP " + "WHERE file_name = '{1}' AND solver_name = '{0}' AND solve_status = 'solving' ", username, filename); //cmd.CommandText = "SELECT dbo.file_list.file_name FROM dbo.file_list"; //SqlDataReader reader = cmd.ExecuteReader(); //while (reader.Read()) //{ // this.file_list_box.Items.Add(reader[0].ToString()); //} //reader.Dispose(); if (cmd.ExecuteNonQuery() == 0) throw new Exception("DB Update failed"); con.Close(); con.Dispose(); File_List fl = new File_List(username, caller); fl.Show(); this.Hide(); //this.Close(); } catch (Exception ee) { MessageBox.Show("Database error - Finishing failed.\n" + ee.StackTrace.ToString()); //Application.Exit(); } // save file if (error_only) (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Empty; this.dataGridView1.Sort(dataGridView1.Columns["serial"], ListSortDirection.Ascending); StreamWriter sw = new StreamWriter(@"Backup\" + filename + ".SLV"); for (int row = 0; row < dataGridView1.RowCount; row++) { sw.WriteLine("{0,12}{1,4}{3,3}{4,6}{5,11}{6,28}{7,10}{8,32}{9,32}{2,40}", dataGridView1.Rows[row].Cells[0].Value, //id dataGridView1.Rows[row].Cells[1].Value, //serial dataGridView1.Rows[row].Cells[2].Value, //err_dscr dataGridView1.Rows[row].Cells[3].Value, //exam_code dataGridView1.Rows[row].Cells[4].Value, //pap_code dataGridView1.Rows[row].Cells[5].Value, //regi dataGridView1.Rows[row].Cells[6].Value, //qr_code dataGridView1.Rows[row].Cells[7].Value, //scrpt_no dataGridView1.Rows[row].Cells[8].Value, //litho_1 dataGridView1.Rows[row].Cells[9].Value, //litho_2 "" ); } sw.Dispose(); } }