// Delete box is and its product module data(done by only the user user) private void btnDeleteBoxId_Click(object sender, EventArgs e) { // Ask 2 times to the user for check DialogResult result1 = MessageBox.Show("Do you really delete this box id's all the serial data?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result1 == DialogResult.Yes) { DialogResult result2 = MessageBox.Show("Are you really sure? Please select NO if you are not sure.", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (result2 == DialogResult.Yes) { string boxid = txtBoxId.Text; string sql = "delete from product_serial where boxid = '" + boxid + "'"; string sql1 = "delete from box_id where boxid = '" + boxid + "'"; ShSQL tf = new ShSQL(); tf.sqlExecuteNonQuery(sql, true); tf.sqlExecuteNonQuery(sql1, true); dtOverall.Clear(); // Update datagridviw updateDataGripViews(dtOverall, ref dgvProductSerial); } } }
// Login button click event: match account and pass private void btnLogIn_Click(object sender, EventArgs e) { string sql = null; string user = null; string pass = null; bool login = false; user = cmbUserName.Text; if (user != null) { ShSQL tf = new ShSQL(); sql = "select pass FROM s_user WHERE suser='******'"; pass = tf.sqlExecuteScalarString(sql); sql = "select loginstatus FROM s_user WHERE suser='******'"; login = tf.sqlExecuteScalarBool(sql); if (pass == txtPassword.Text) { if (login) { DialogResult reply = MessageBox.Show("This user account is currently used by other user," + System.Environment.NewLine + "or the log out last time had a problem." + System.Environment.NewLine + "Do you log in with this account ?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (reply == DialogResult.No) { return; } } // turn the login status into TRUE sql = "UPDATE s_user SET loginstatus=true WHERE suser='******'"; bool res = tf.sqlExecuteNonQuery(sql, false); // Generate child form "frmBoxid" and add delegate event: // when the child form is closed, this parent login form is also to be closed frmBoxid f1 = new frmBoxid(); f1.RefreshEvent += delegate(object sndr, EventArgs excp) { // when frmBoxid(child) is closed, change the login status into FALSE, then close the this form(parent) sql = "UPDATE s_user SET loginstatus=false WHERE suser='******'"; res = tf.sqlExecuteNonQuery(sql, false); //this.Hide(); }; f1.updateControls(user); this.Hide(); f1.ShowDialog(); this.Show(); } else if (pass != txtPassword.Text) { MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
// 登録済のシリアルおよびその付帯情報を、UPDATE文で置き換える private void btnReplace_Click(object sender, EventArgs e) { string snBefore = txtBefore.Text; string snAfter = txtAfter.Text; string filterkey = decideReferenceTable(snAfter); if (snAfter == String.Empty) { return; } setSerialInfoAndTesterResult(snAfter); string sql = "update product_serial set " + "serialno='" + dataTable.Rows[0]["serialno"] + "', " + "model='" + dataTable.Rows[0]["model"] + "', " + "lot='" + dataTable.Rows[0]["lot"] + "', " + "fact='" + dataTable.Rows[0]["fact"] + "', " + "process='" + dataTable.Rows[0]["process"] + "', " + "linepass='******', " + "testtime='" + dataTable.Rows[0]["testtime"] + "' " + "where serialno='" + txtBefore.Text + "'"; System.Diagnostics.Debug.Print(sql); ShSQL tf = new ShSQL(); bool res = tf.sqlExecuteNonQuery(sql, true); if (res) { //親フォームfrmBoxidのデータグリットビューを更新するため、デレゲートイベントを発生させる this.RefreshEvent(this, new EventArgs()); Close(); } }
// Sub procedure: Issue new box id private string getNewBoxId() { m_model = dtOverall.Rows[0]["model"].ToString(); string sql = "select MAX(boxid) FROM box_id where boxid like '" + m_model + "%'"; System.Diagnostics.Debug.Print(sql); ShSQL yn = new ShSQL(); string boxIdOld = yn.sqlExecuteScalarString(sql); DateTime dateOld = new DateTime(0); long numberOld = 0; string boxIdNew; if (m_model == "BMS69") { if (!string.IsNullOrEmpty(boxIdOld)) { dateOld = DateTime.ParseExact(VBStrings.Mid(boxIdOld, 7, 6), "yyMMdd", CultureInfo.InvariantCulture); numberOld = long.Parse(VBStrings.Right(boxIdOld, 2)); } if (dateOld != DateTime.Today) { boxIdNew = m_model + "-" + DateTime.Today.ToString("yyMMdd") + "01"; } else { boxIdNew = m_model + "-" + DateTime.Today.ToString("yyMMdd") + (numberOld + 1).ToString("00"); } } else { if (boxIdOld != string.Empty) { dateOld = DateTime.ParseExact(VBStrings.Mid(boxIdOld, 6, 6), "yyMMdd", CultureInfo.InvariantCulture); numberOld = long.Parse(VBStrings.Right(boxIdOld, 2)); } if (dateOld != DateTime.Today) { boxIdNew = m_model + "-" + DateTime.Today.ToString("yyMMdd") + "01"; } else { boxIdNew = m_model + "-" + DateTime.Today.ToString("yyMMdd") + (numberOld + 1).ToString("00"); } } sql = "INSERT INTO box_id(" + "boxid," + "suser," + "printdate) " + "VALUES(" + "'" + boxIdNew + "'," + "'" + user + "'," + "'" + DateTime.Now.ToString() + "')"; System.Diagnostics.Debug.Print(sql); yn.sqlExecuteNonQuery(sql, false); return(boxIdNew); }