Exemplo n.º 1
0
 void FrmUsers_Load(object sender, EventArgs e)
 {
     //throw new NotImplementedException();
     RIPP.NIR.Controls.StyleTool.FormatGrid(ref this.dataGridView1);
     this.SetHeader();
     using (var db = new NIRCeneterEntities())
     {
         var lst = db.S_User;
         foreach (var u in lst)
         {
             var row = new mydatarow()
             {
                 User     = u,
                 IsEdited = false,
                 IsNew    = false
             };
             row.CreateCells(this.dataGridView1,
                             u.loginName,
                             u.IsDeleted ? "停用" : "正常",
                             "******",
                             u.realName,
                             u.tel,
                             u.email,
                             u.Role.GetDescription());
             //显示不同的颜色
             if ((this._user.Role == RoleEnum.Engineer && u.Role == RoleEnum.Engineer) && this._user.ID != u.ID)
             {
                 row.DefaultCellStyle.BackColor = Color.FromArgb(240, 240, 240);
             }
             this.dataGridView1.Rows.Add(row);
         }
     }
 }
Exemplo n.º 2
0
        private void btnSetOk_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count == 0)
            {
                MessageBox.Show("请先选中需要启用的用户。");
                return;
            }

            var row = this.dataGridView1.SelectedRows[0] as mydatarow;

            if (row == null || row.User == null)
            {
                return;
            }
            if (MessageBox.Show(string.Format("是否启用 {0} ?", row.User.loginName),
                                "信息提示",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                using (var db = new NIRCeneterEntities())
                {
                    var u = db.S_User.Where(d => d.ID == row.User.ID).FirstOrDefault();
                    if (u != null)
                    {
                        u.IsDeleted = false;
                        db.SaveChanges();
                    }
                    row.User.IsDeleted           = false;
                    row.Cells["isdeleted"].Value = "启用";
                    //this.dataGridView1.Rows.RemoveAt(row.Index);
                }
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            var row = this.dataGridView1.SelectedRows[0] as myrow;

            if (row == null)
            {
                return;
            }
            this.lblStatu.Text = "正在保存";
            this.Enabled       = false;
            row.Cells[1].Value = true;
            var lstnames = new List <string>();

            for (int r = 0; r < this.dataGridView1.Rows.Count; r++)
            {
                if (Convert.ToBoolean(this.dataGridView1[1, r].Value))
                {
                    lstnames.Add(Convert.ToString(this.dataGridView1[0, r].Value));
                }
            }

            Action a = () =>
            {
                //检查MD5
                var md5 = Tool.GetMD5HashFromFile(row.FullPath);
                using (var db = new NIRCeneterEntities())
                {
                    var modeldb = db.AllMethod.Where(m => m.MD5Str == md5).FirstOrDefault();
                    if (modeldb == null)
                    {
                        modeldb = new AllMethod()
                        {
                            AddTime  = DateTime.Now,
                            FullPath = row.FullPath,
                            MD5Str   = md5,
                            UserID   = this._user.ID,
                            Contents = Serialize.ObjectToByte(row.Model)
                        };
                        db.AllMethod.AddObject(modeldb);
                        db.SaveChanges();
                    }
                    this._config.AvailableModelNames = lstnames;
                    this._config.ModelDefaultPath    = row.FullPath;
                    this._config.ModelDefaultID      = modeldb.ID;
                    this._config.Save();
                }
                this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                this.Close();
            };

            this.Invoke(a);
        }
Exemplo n.º 4
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     using (var db = new NIRCeneterEntities())
     {
         var item = db.S_User.Where(d => d.ID == this._user.ID).FirstOrDefault();
         if (item != null)
         {
             item.realName = this.txbRealname.Text;
             item.email    = this.txbEmail.Text;
             item.tel      = this.txbPhone.Text;
             if (!string.IsNullOrWhiteSpace(this.txbpassword.Text.Trim()))
             {
                 item.password = RIPP.Lib.Security.SecurityTool.BuildPassword(this.txbpassword.Text.Trim());
             }
             db.SaveChanges();
         }
         this.DialogResult = System.Windows.Forms.DialogResult.OK;
     }
 }
Exemplo n.º 5
0
 private void label3_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("是否清除数据库中的所有数据?", "提示", MessageBoxButtons.YesNo,
                         MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
     {
         Action a = () =>
         {
             using (var db = new NIRCeneterEntities())
             {
                 var lst = db.Specs;
                 foreach (var s in lst)
                 {
                     db.Specs.DeleteObject(s);
                 }
                 db.SaveChanges();
             }
         };
         a.BeginInvoke(null, null);
     }
 }
Exemplo n.º 6
0
        void FrmLogon_Load(object sender, EventArgs e)
        {
            this.btnLogon.Enabled = false;
            this.AcceptButton     = this.btnLogon;

            Action sa = () =>
            {
                this.showinfo("正在初始化数值计算库...");
                RIPP.NIR.Data.Tools.Init();
                this._isInit = true;
                if (this.progressBar1.InvokeRequired)
                {
                    ThreadStart ss = () => { this.progressBar1.Visible = false; };
                    this.progressBar1.Invoke(ss);
                }
                else
                {
                    this.progressBar1.Visible = false;
                }
                this.showinfo("数值计算库初始化完成");

                if (this._islogin)
                {
                    if (this.InvokeRequired)
                    {
                        ThreadStart ss = () => { this.DialogResult = System.Windows.Forms.DialogResult.OK; };
                        this.Invoke(ss);
                    }
                    else
                    {
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                }
            };

            sa.BeginInvoke(null, null);
            //检查数据库
            Action a = () =>
            {
                try
                {
                    string str = RIPP.Lib.Security.SecurityTool.BuildPassword("2");
                    using (var db = new NIRCeneterEntities())
                    {
                        db.S_User.Where(d => d.ID == 4).FirstOrDefault();
                    }
                    //初始化Matlab相关

                    if (this.btnLogon.InvokeRequired)
                    {
                        ThreadStart s = () => { this.btnLogon.Enabled = true; };
                        this.lblInfo.Invoke(s);
                    }
                    else
                    {
                        this.btnLogon.Enabled = true;
                    }
                }
                catch (Exception ex)
                {
                    this.showinfo("数据库连接失败,请检查配置文件。");
                    Log.Error(ex.ToString());
                }
            };

            a.BeginInvoke(null, null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 按钮|登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogon_Click(object sender, EventArgs e)
        {
            btnLogon.Enabled = false;
            //this.lblInfo.Text = "";
            string username = this.txbLoginName.Text.Trim();
            string password = this.txbPsw.Text.Trim();

            //先判断是否为RIPP
            if (username == "1")
            {
                if (password == "1")
                {
                    this.LogUser = new S_User()
                    {
                        Role = RoleEnum.RIPP
                    };
                    this._islogin         = true;
                    this.btnLogon.Enabled = false;
                    if (this._isInit)
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    this.lblInfo.Text     = "密码不正确,请重试!";
                    this.btnLogon.Enabled = true;
                }
            }
            else
            {
                using (var db = new NIRCeneterEntities())
                {
                    var user = db.S_User.Where(d => d.loginName == username).FirstOrDefault();
                    if (user == null)
                    {
                        this.lblInfo.Text     = "用户名不存在,请重试!";
                        this.btnLogon.Enabled = true;
                    }
                    else
                    {
                        if (user.password != RIPP.Lib.Security.SecurityTool.BuildPassword(password))
                        {
                            this.lblInfo.Text     = "密码不正确,请重试!";
                            this.btnLogon.Enabled = true;
                        }
                        else if (user.IsDeleted)
                        {
                            this.lblInfo.Text     = "您的账户已被停用,请重试!";
                            this.btnLogon.Enabled = true;
                        }
                        else
                        {
                            this.LogUser          = user;
                            this._islogin         = true;
                            this.btnLogon.Enabled = false;
                            if (this._isInit)
                            {
                                this.DialogResult = DialogResult.OK;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void Save()
        {
            if (this._table == null)
            {
                return;
            }
            using (var db = new NIRCeneterEntities())
            {
                var lst = db.Properties.Where(d => d.TableID == (int)this._table.Table);
                foreach (var i in lst)
                {
                    db.Properties.DeleteObject(i);
                }

                var needadd = new List <Busi.Properties>();
                for (int r = 0; r < this.dataGridView1.RowCount; r++)
                {
                    int d  = 0;
                    var c1 = Convert.ToString(this.dataGridView1[0, r].Value);
                    var c2 = Convert.ToString(this.dataGridView1[5, r].Value);
                    if (!string.IsNullOrWhiteSpace(c1))
                    {
                        var s = Convert.ToString(this.dataGridView1[4, r].Value);
                        if (int.TryParse(s, out d))
                        {
                            var name  = this.dataGridView1[0, r].Value ?? "";
                            var name1 = this.dataGridView1[1, r].Value ?? "";
                            var code  = this.dataGridView1[2, r].Value ?? "";
                            var units = this.dataGridView1[3, r].Value ?? "";
                            needadd.Add(new Busi.Properties()
                            {
                                Name      = name.ToString().Trim(),
                                Name1     = name1.ToString().Trim(),
                                Code      = code.ToString().Trim(),
                                Units     = units.ToString().Trim(),
                                Eps       = d,
                                ColumnIdx = 1,
                                Idx       = r,
                                TableID   = (int)this._table.Table
                            });
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(c2))
                    {
                        var s = Convert.ToString(this.dataGridView1[9, r].Value);
                        if (int.TryParse(s, out d))
                        {
                            var name  = this.dataGridView1[5, r].Value ?? "";
                            var name1 = this.dataGridView1[6, r].Value ?? "";
                            var code  = this.dataGridView1[7, r].Value ?? "";
                            var units = this.dataGridView1[8, r].Value ?? "";
                            needadd.Add(new Busi.Properties()
                            {
                                Name      = name.ToString().Trim(),
                                Name1     = name1.ToString().Trim(),
                                Code      = code.ToString().Trim(),
                                Units     = units.ToString().Trim(),
                                Eps       = d,
                                ColumnIdx = 2,
                                Idx       = r,
                                TableID   = (int)this._table.Table
                            });
                        }
                    }
                }
                foreach (var i in needadd)
                {
                    db.Properties.AddObject(i);
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 9
0
        private void edituser(int rowid)
        {
            if (rowid >= this.dataGridView1.Rows.Count)
            {
                return;
            }
            var row = this.dataGridView1.Rows[rowid] as mydatarow;

            if (row == null || row.User == null)
            {
                return;
            }
            var loginName = Convert.ToString(row.Cells["loginName"].Value).Trim();
            var password  = Convert.ToString(row.Cells["password"].Value).Trim();
            var realName  = Convert.ToString(row.Cells["realName"].Value).Trim();
            var tel       = Convert.ToString(row.Cells["tel"].Value).Trim();
            var email     = Convert.ToString(row.Cells["email"].Value).Trim();
            var role      = Convert.ToString(row.Cells["role"].Value).Trim();
            var isdelted  = Convert.ToString(row.Cells["isdeleted"].Value).Trim();

            if (string.IsNullOrWhiteSpace(loginName) || string.IsNullOrWhiteSpace(password))
            {
                return;
            }

            using (var db = new NIRCeneterEntities())
            {
                S_User user;
                if (row.User.ID == 0)
                {
                    user = new S_User();
                }
                else
                {
                    user = db.S_User.Where(d => d.ID == row.User.ID).FirstOrDefault();
                }
                //检查登录名是否重复
                if (db.S_User.Where(d => d.loginName == loginName && d.ID != user.ID).Count() > 0)
                {
                    MessageBox.Show("登录名重复,请重新输入!");
                    return;
                }

                if (user == null)
                {
                    return;
                }
                user.loginName = loginName;
                if (password != "******")
                {
                    user.password = RIPP.Lib.Security.SecurityTool.BuildPassword(password);
                }
                user.realName  = realName;
                user.tel       = tel;
                user.email     = email;
                user.roleID    = (int)(RoleEnum.Engineer.GetDescription() == role ? RoleEnum.Engineer : RoleEnum.Operater);
                user.IsDeleted = isdelted == "停用" ? true : false;

                if (user.ID == 0)
                {
                    db.S_User.AddObject(user);
                }
                db.SaveChanges();
                row.User = user;
            }
        }