// サブサブプロシージャ:グリットビュー右端にボタンを追加 private void addButtonsToDataGridView(DataGridView dgv) { bool adm_flag = false; TfSQL flag = new TfSQL(); bool fl = flag.sqlExecuteScalarBool("select admin_flag from qc_user where qcuser = '******'"); if (fl == true) { adm_flag = true; } Open = new DataGridViewButtonColumn(); Open.Text = "Open"; Open.UseColumnTextForButtonValue = true; Open.Width = 45; dgv.Columns.Add(Open); if (adm_flag == true) { btnDelete.Visible = true; } }
// ロード時の処理 private void Form1_Load(object sender, EventArgs e) { //フォームの場所を指定 this.Left = 0; this.Top = 0; dtInspectItems = new DataTable(); dtLine = new DataTable(); defineItemTable(ref dtInspectItems); defineLineTable(ref dtLine); getComboListFromDB(ref cmbModel); updateDataGripViews(ref dgvMeasureItem, true); load_cmb = false; // loadline(); TfSQL flag = new TfSQL(); bool fl = flag.sqlExecuteScalarBool("select admin_flag from qc_user where qcuser = '******'"); if (fl == true) { adm_flag = true; } if (adm_flag == true) { btnEditMaster.Enabled = true; } //Exit app if user has been log in by another device and log in again string ipadd = flag.sqlExecuteScalarString("select ip_address from qc_user where qcuser = '******'"); if (ipadd == "null") { flag.sqlExecuteScalarString("UPDATE qc_user SET ip_address = '" + _ip + "' where qcuser = '******'"); } if (ipadd != "null" && ipadd != _ip) { DialogResult res = MessageBox.Show("User is logged in " + _ip + "," + System.Environment.NewLine + "Do you want to log out and log in again ?", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question); if (res == DialogResult.OK) { Application.Exit(); } } //New option try { if (!Directory.Exists(@"D:\Database IPQC\")) { Directory.CreateDirectory(@"D:\Database IPQC\"); } if (File.Exists(@"D:\Database IPQC\Template.xlsx")) { File.Delete(@"D:\Database IPQC\Template.xlsx"); } File.Copy(@"\\192.168.145.7\checksheet\Template.xlsx", @"D:\Database IPQC\Template.xlsx"); if (File.Exists(@"D:\Database IPQC\Template-CheckUCL.xlsx")) { File.Delete(@"D:\Database IPQC\Template-CheckUCL.xlsx"); } File.Copy(@"\\192.168.145.7\checksheet\Template-CheckUCL.xlsx", @"D:\Database IPQC\Template-CheckUCL.xlsx"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// ユーザーログイン時、パスワードとログイン状態の確認(2重ログインの防止) private void btnLogIn_Click(object sender, EventArgs e) { if (btnLogIn.Text == "Log In") { TfSQL tf = new TfSQL(); string logt = tf.sqlExecuteScalarString("select login_times from qc_user where qcuser = '******'"); if (logt == "0") { grLogin.Text = "Change Default Password"; lblUser.Text = "New Password"; txtPwd.Size = new Size(100, 20); txtPwd.Location = new Point(123, 47); lblPass.Text = "Confirm Password"; txtPassword.Size = new Size(100, 20); txtPassword.Location = new Point(123, 87); btnLogIn.Text = "Change Password"; btnLogIn.Enabled = false; txtPassword.ResetText(); txtPwd.ResetText(); txtPwd.Visible = true; txtPwd.Focus(); cmbUserName.Visible = false; btnChangePass.Visible = false; } else { string sql = null; string user = null; string pass = null; string ip = null; bool login = false; user = cmbUserName.Text; if (user != null) { sql = "select pass FROM qc_user WHERE qcuser='******'"; pass = tf.sqlExecuteScalarString(sql); sql = "select loginstatus FROM qc_user WHERE qcuser='******'"; login = tf.sqlExecuteScalarBool(sql); sql = "select ip_address from qc_user where qcuser = '******'"; ip = tf.sqlExecuteScalarString(sql); GetMD5(txtPassword.Text); if (pass == str_md5) { if (login && ip != "null" && ip != lblIP.Text) { DialogResult reply = MessageBox.Show("This user account is currently used by " + ip + "," + System.Environment.NewLine + "or the log out last time had a problem.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); sql = "UPDATE qc_user SET loginstatus=false, ip_address = '" + lblIP.Text + "' WHERE qcuser='******'"; bool res1 = tf.sqlExecuteNonQuery(sql, false); return; } //Check IP Address if (ip == "null") { tf.sqlExecuteScalarString("UPDATE qc_user SET ip_address = '" + lblIP.Text + "' where qcuser = '******'"); } // ログイン状態をTRUEへ変更 sql = "UPDATE qc_user SET loginstatus=true WHERE qcuser='******'"; bool res = tf.sqlExecuteNonQuery(sql, false); // 子フォームForm1を表示し、デレゲートイベントを追加: frmItem f1 = new frmItem(); f1.RefreshEvent += delegate(object sndr, EventArgs excp) { // Form1を閉じる際、ログイン状態をFALSEへ変更し、当フォームForm5も閉じる sql = "UPDATE qc_user SET loginstatus=false, ip_address = 'null' WHERE qcuser='******'"; res = tf.sqlExecuteNonQuery(sql, false); this.Visible = true; txtPassword.ResetText(); }; f1.updateControls(user, lblIP.Text); f1.Show(); this.Visible = false; } else if (pass != txtPassword.Text) { MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.ResetText(); } } } } else { if (txtPwd.Text != txtPassword.Text) { lblStatus.Text = "Password is not avaliable!"; lblStatus.ForeColor = Color.Red; } else { string pass = txtPwd.Text; GetMD5(pass); TfSQL up = new TfSQL(); up.sqlExecuteScalarString("update qc_user set pass = '******' where qcuser = '******'"); up.sqlExecuteScalarString("update qc_user set login_times = '1' where qcuser = '******'"); btnLogIn.Text = "Log In"; lblUser.Text = "Username:"******"Password:"******"Your password has been changed!", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result == DialogResult.OK) { login(); } } } }
private void login() { string sql = null; string user = null; string pass = null; string ip = null; bool login = false; user = cmbUserName.Text; if (user != null) { TfSQL tf = new TfSQL(); sql = "select pass FROM qc_user WHERE qcuser='******'"; pass = tf.sqlExecuteScalarString(sql); sql = "select loginstatus FROM qc_user WHERE qcuser='******'"; login = tf.sqlExecuteScalarBool(sql); sql = "select ip_address from qc_user where qcuser = '******'"; ip = tf.sqlExecuteScalarString(sql); //Check IP Address if (ip == "null") { tf.sqlExecuteScalarString("UPDATE qc_user SET ip_address = '" + lblIP.Text + "'"); } GetMD5(txtPassword.Text); if (pass == str_md5) { if (login && ip != "null" && ip != lblIP.Text) { DialogResult reply = MessageBox.Show("This user account is currently used by " + ip + "," + System.Environment.NewLine + "or the log out last time had a problem.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); return; } // ログイン状態をTRUEへ変更 sql = "UPDATE qc_user SET loginstatus=true WHERE qcuser='******'"; bool res = tf.sqlExecuteNonQuery(sql, false); // 子フォームForm1を表示し、デレゲートイベントを追加: frmItem f1 = new frmItem(); f1.RefreshEvent += delegate(object sndr, EventArgs excp) { // Form1を閉じる際、ログイン状態をFALSEへ変更し、当フォームForm5も閉じる sql = "UPDATE qc_user SET loginstatus=false, ip_address = 'null' WHERE qcuser='******'"; res = tf.sqlExecuteNonQuery(sql, false); this.Visible = true; txtPassword.ResetText(); }; f1.updateControls(user, lblIP.Text); f1.Show(); this.Visible = false; } else if (pass != txtPassword.Text) { MessageBox.Show("Password does not match", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.ResetText(); } } }
// ロード時の処理 private void frmScale_Load(object sender, EventArgs e) { // 当フォームの表示場所を指定 this.Left = 300; this.Top = 15; if (cmbLine.Text == "") { btnMeasure.Enabled = false; } //Exit app if user has been log in by another device TfSQL flag = new TfSQL(); string ipadd = flag.sqlExecuteScalarString("select ip_address from qc_user where qcuser = '******'"); bool expmiss = flag.sqlExecuteScalarBool("select export_permission from qc_user where qcuser = '******'"); if (ipadd == "null") { flag.sqlExecuteScalarString("UPDATE qc_user SET loginstatus=true, ip_address = '" + _ip + "' where qcuser = '******'"); } if (ipadd != "null" && ipadd != _ip) { DialogResult res = MessageBox.Show("User is logged in " + _ip + "," + System.Environment.NewLine + "Do you want to log out and log in again ?", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Question); if (res == DialogResult.OK) { Application.Exit(); } } if (txtUser.Text != "Admin") { string[] a = txtUser.Text.Split('_'); //User permission if (a[1] != "CHK" && txtUser.Text != "Admin") { btnMeasure.Enabled = false; btnRegister.Enabled = false; btnDelete.Enabled = false; } if (expmiss == false && txtUser.Text != "Admin") { btnExport.Enabled = false; } } // DATETIMEPICKERを10日前の日付にする dtpSet10daysBefore(dtpLotFrom); // DATETIMEPICKERの分以下を切り上げる dtpRoundUpHour(dtpLotTo); // DATETIMEPICKERの分以下を下げる dtpRounddownHour(dtpLotInput); // 感知された1つ目のシリアルポートを選択し、オープンする initializePort(); // 各種処理用のテーブルを生成してデータを読み込む dtBuffer = new DataTable(); defineBufferAndHistoryTable(ref dtBuffer); dtHistory = new DataTable(); defineBufferAndHistoryTable(ref dtHistory); readDtHistory(ref dtHistory); dtUpLowIns = new DataTable(); setLimitSetAndCommand(ref dtUpLowIns); //addButtonsToDataGridView(dgvHistory); // グリットビューの更新 updateDataGripViews(dtBuffer, dtHistory, ref dgvBuffer, ref dgvHistory); // グリットビュー右端にボタンを追加(初回のみ) addButtonsToDataGridView(dgvHistory); }