Exemple #1
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (tbNewPwd.Text.Trim().Equals(""))
            {
                MessageBox.Show("New Password is empty!", "Error");
            }
            else if (!tbNewPwd.Text.Equals(tbConfirmPwd.Text))
            {
                MessageBox.Show("New password and confirm password does not match!", "Error");
            }
            else if (!checkOldPwd(tbUserID.Text, tbOldPwd.Text))
            {
                MessageBox.Show("Old password do not match.", "Check Password Fail");
            }
            else
            {
                DBUtil dBUtil = new DBUtil();
                Dictionary <string, object> keyValues = new Dictionary <string, object>();
                string strSql = "UPDATE account SET PASSWORD = MD5(@password), " +
                                "modify_user = @modify_user, " +
                                "modify_timestamp = NOW() " +
                                "WHERE user_id = @user_id ";

                keyValues.Add("@user_id", tbUserID.Text.Trim());
                keyValues.Add("@password", tbNewPwd.Text.Trim());
                keyValues.Add("@modify_user", Global.currentUser);
                dBUtil.ExecuteNonQuery(strSql, keyValues);
                SanwaUtil.addActionLog("GUI.FormChgPwd", "Change password", Global.currentUser, "變更本人密碼");
                MessageBox.Show("變更密碼成功!!", "Success");
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Exemple #2
0
        private void btnChange_Click_1(object sender, EventArgs e)
        {
            string oldRecipeId = SystemConfig.Get().CurrentRecipe;
            string newRecipeId = cbRecipe.SelectedItem.ToString();

            using (var form = new FormConfirm("是否變更生產 Recipe:" + oldRecipeId + "=>" + newRecipeId))
            {
                var result = form.ShowDialog();
                if (result == DialogResult.OK)
                {
                    SystemConfig config = SystemConfig.Get();
                    config.CurrentRecipe = cbRecipe.SelectedItem.ToString();
                    config.Save();
                    FormMainUpdate.UpdateRecipe(config.CurrentRecipe);
                    SanwaUtil.addActionLog("Recipe", "Change", Global.currentUser, "變更生產 Recipe:" + oldRecipeId + "=>" + newRecipeId);
                    MessageBox.Show("Change recipe completed.", "Success");
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Cancel.", "Notice");
                }
            }
        }
Exemple #3
0
        public static void UpdateLogoutInfo()
        {
            try
            {
                Form form = Application.OpenForms["FormMain"];

                if (form == null)
                {
                    return;
                }

                if (form.InvokeRequired)
                {
                    UpdateLogout ph = new UpdateLogout(UpdateLogoutInfo);
                    form.BeginInvoke(ph);
                }
                else
                {
                    ILog log = LogManager.GetLogger("Database");
                    //lbl_login_name
                    Label  lbl_login_id    = form.Controls.Find("lbl_login_id", true).FirstOrDefault() as Label;
                    Label  lbl_login_name  = form.Controls.Find("lbl_login_name", true).FirstOrDefault() as Label;
                    Label  lbl_login_group = form.Controls.Find("lbl_login_group", true).FirstOrDefault() as Label;
                    Label  lbl_login_date  = form.Controls.Find("lbl_login_date", true).FirstOrDefault() as Label;
                    string user_id         = lbl_login_id.Text;
                    string user_name       = lbl_login_name.Text;
                    if (lbl_login_id != null)
                    {
                        lbl_login_id.Text = "ID";
                    }
                    if (lbl_login_name != null)
                    {
                        lbl_login_name.Text = "Name";
                    }
                    if (lbl_login_group != null)
                    {
                        lbl_login_group.Text = "Group";
                    }
                    if (lbl_login_date != null)
                    {
                        lbl_login_date.Text = "";
                    }
                    Button btn = form.Controls.Find("btnLogInOut", true).FirstOrDefault() as Button;
                    btn.Text = "Login";
                    string msg = "{\"user_id\": " + user_id + ", \"name\": \"" + user_name + "\", \"action\": \"Logout\"}";
                    log.Info(msg);
                    //SanwaUtil.addActionLog("Authority", "Logout", user_id);// add record to log_system_action
                    SanwaUtil.addActionLog("Authority", "Logout", user_id, "使用者登出");// add record to log_system_action
                }
            }
            catch
            {
                logger.Error("UpdateLoginInfo: Update fail.");
            }
        }
Exemple #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            Boolean result = false;
            //set SQL
            StringBuilder sql = new StringBuilder();

            sql.Append("\n SELECT user_id, user_name, user_group_id");
            sql.Append("\n   FROM account ");
            sql.Append("\n  WHERE user_id = @user_id ");
            sql.Append("\n    AND password = MD5(@password)");
            //set parameter
            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("@user_id", tbUserID.Text);
            param.Add("@password", tbPassword.Text);
            //Query
            DBUtil          dBUtil = new DBUtil();
            DataTableReader rs     = dBUtil.GetDataReader(sql.ToString(), param);

            if (rs != null)
            {
                //Console.Write("\n ID:" + rs["user_id"] + " Password:"******"password"] + " MD5:" + rs["md5"]);

                string user_id       = "";
                string user_name     = "";
                string user_group_id = "";
                while (rs.Read())
                {
                    user_id       = (string)rs["user_id"];
                    user_name     = (string)rs["user_name"];
                    user_group_id = (string)rs["user_group_id"];
                    result        = true;
                }
                rs.Close();
                if (result)
                {
                    AuthorityUpdate.UpdateLoginInfo(user_id, user_name, user_group_id);
                    string msg = "{\"user_id\": " + user_id + ", \"name\": \"" + user_name + "\", \"action\": \"Login\"}";
                    log.Info(msg);
                    //SanwaUtil.addActionLog("Authority", "Login", user_id);// add record to log_system_action
                    SanwaUtil.addActionLog("Authority", "Login", user_id, "使用者登錄");// add record to log_system_action
                    Global.currentUser = user_id;
                    this.DialogResult  = DialogResult.OK;
                    //log.Debug(msg);
                    this.Close();
                }
                else
                {
                    //this.DialogResult = DialogResult.Cancel; //不能加這行,會跳出
                    MessageBox.Show("Please check data and login again.", "Login Fail");
                    return;
                }
            }
        }
Exemple #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if ((DataTable)dgvlsbAlarmData.DataSource == null || ((DataTable)dgvlsbAlarmData.DataSource).Rows.Count == 0)
            {
                MessageBox.Show("The grid data does not exist.", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                return;
            }

            if (MessageBox.Show("Are you sure save the setting?", this.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) != DialogResult.Yes)
            {
                return;
            }

            string        strSql = string.Empty;
            StringBuilder sbTemp = new StringBuilder();
            Dictionary <string, object> keyValues = new Dictionary <string, object>();
            DataTable dtTemp = null;

            try
            {
                dtTemp = (DataTable)dgvlsbAlarmData.DataSource;

                strSql = "UPDATE device_code SET " +
                         "is_stop = '{0}' " +
                         "WHERE node_type = '{1}' " +
                         "AND vendor = '{2}' " +
                         "AND category = '{3}' " +
                         "AND code_id = '{4}' " +
                         ";";

                foreach (DataRow dr in dtTemp.Rows)
                {
                    sbTemp.AppendFormat(strSql, dr["is_stop"].ToString(), dr["node_type"].ToString(), dr["vendor"].ToString(), dr["category"].ToString(), dr["code_id"].ToString());
                }

                dBUtil.ExecuteNonQuery(sbTemp.ToString(), null);

                MessageBox.Show("Done it.", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                Form  form   = Application.OpenForms["FormMain"];
                Label Signal = form.Controls.Find("lbl_login_id", true).FirstOrDefault() as Label;
                SanwaUtil.addActionLog("Adam.Menu.SystemSetting", "FormAlarmEventSet", Signal.Text);

                FormAlarmEventSet_Load(sender, e);
                dgvlsbAlarmData.DataSource = null;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Exemple #6
0
        public FormMain()
        {
            InitializeComponent();
            XmlConfigurator.Configure();
            Initialize();

            HostControl = new RorzeInterface(this);
            RouteCtrl   = new RouteControl(HostControl);
            AlmMapping  = new AlarmMapping();

            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Location      = new System.Drawing.Point(-200, 0);

            SanwaUtil.addPartition();
            SanwaUtil.dropPartition();
            ThreadPool.QueueUserWorkItem(new WaitCallback(DBUtil.consumeSqlCmd));
        }