Пример #1
0
 public UserForm(User u, DataTable roles, DataTable users)
 {
     InitializeComponent();
       user = u;
       _roles = roles;
       _users = users;
 }
Пример #2
0
        private void button5_Click(object sender, EventArgs e)
        {
            user.SetId(_client.GetCurIdentity("User") + 1);

              UserForm uf = new UserForm(user, _roles, _users);
              uf.ShowDialog();

              user = uf.user;

              if (user.Id != 0)
              {
            textBoxUserID.Text = user.Id.ToString();
              }
        }
Пример #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Enter, authentification and authorization

              EnterForm ef = new EnterForm(client);

              ef.ShowDialog();

              _user = ef.user;

              if (_user.Id == 0)
              {
            Close();
              }
              else
              {
            _db = client.GetDatabaseAccess(_user.Id);//Getting database

            //Hiding data in relation with user rights and making data bindings
            if (!_db.Rights["Products"])
            {
              tabControlMain.TabPages["Products"].Dispose();
            }
            if (!_db.Rights["Order"])
            {
              tabControlMain.TabPages["Order"].Dispose();
            }
            if (!_db.Rights["Clients"])
            {
              tabControlMain.TabPages["Clients"].Dispose();
            }
            if (!_db.Rights["Reports"])
            {
              tabControlMain.TabPages["Reports"].Dispose();
            }
            if (!_db.Rights["Management"])
            {
              tabControlMain.TabPages.RemoveByKey("Management");
            }
            var emplRow = _db._ds.Tables["Employee"].AsEnumerable().FirstOrDefault(r => r.Field<int>("UserId") == _user.Id);

            if (emplRow != null)
            {
              _employee = new Employee
              {
            Id = emplRow.Field<int>("Id"),
            LastName = emplRow.Field<string>("LastName"),
            FirstName = emplRow.Field<string>("FirstName"),
            MiddleName = emplRow.Field<string>("MiddleName"),
            DepartmentId = emplRow.Field<int>("DepartmentId"),
            UserId = emplRow.Field<int>("UserId"),
            AcceptanceDate = emplRow.Field<DateTime>("AcceptanceDate"),
            Bonuses = emplRow.Field<double>("Bonuses"),
            SumOrders = emplRow.Field<double>("SumOrders")
              };

            }

            //for Products TabPage++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            bsProducts = new BindingSource { DataSource = _db._ds.Tables["Product"] };
            dataGridViewProducts.DataSource = bsProducts;
            dataGridViewProducts.Columns[0].Visible = false;
            bindingNavigatorProducts.BindingSource = bsProducts;

            ProductsBinding();

            foreach (DataColumn col in _db._ds.Tables["Product"].Columns)
            {
              string item = "";

              switch (col.ColumnName)
              {
            case "Id":
              item = "Номер (Id)";
              break;
            case "Title":
              item = "Наименование";
              break;
            case "Price":
              item = "Цена (+-25%)";
              break;
            case "DepartmentId":
              item = "Отдел";
              break;
            case "ProduserId":
              item = "Поставщик";
              break;
            case "Quantity":
              item = "Количество (+-25%)";
              break;
            case "CriticalQ":
              item = "Критическое количество (0-нет, 1-да)";
              break;
              }

              if (item != "")
            comboBoxCriteriaFilterProduct.Items.Add(item);
            }

            // for Order TabPage+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            textBoxOrderId.Text = (client.GetCurIdentity("Order") + 1).ToString();

            comboBoxEmpl.Items.Clear();

            if (_employee != null)
            {
              comboBoxEmpl.Items.Add(_employee.LastName + " " + _employee.FirstName + " " + _employee.MiddleName);
              comboBoxEmpl.SelectedIndex = 0;
            }
            else
            {
              string[] empls = (from r in _db._ds.Tables["Employee"].AsEnumerable()
            select (string) r["LastName"] + " " + r["FirstName"] + " " + r["MiddleName"]).ToArray();
              comboBoxEmpl.Items.AddRange(empls);
            }

            //for Clients TabPage+++++++++++++++++++++++++++++++++++++++++++++++++++++++

            bsClients = new BindingSource { DataSource = _db._ds.Tables["Client"] };
            dataGridViewClients.DataSource = bsClients;
            dataGridViewClients.Columns[0].Visible = false;
            bindingNavigatorClients.BindingSource = bsClients;

            if (!_db.Rights["Client_LN"])
            {
              labelLN.Hide();
              textBoxLN.Hide();
            }
            if (!_db.Rights["Client_FN"])
            {
              labelFN.Hide();
              textBoxFN.Hide();
            }
            if (!_db.Rights["Client_MN"])
            {
              labelMN.Hide();
              textBoxMN.Hide();
            }
            if (!_db.Rights["Client_Sex"])
            {
              labelSex.Hide();
              radioButtonClientMale.Hide();
              radioButtonClientFemale.Hide();
            }
            if (!_db.Rights["Client_BD"])
            {
              labelBD.Hide();
              dateTimePickerClientBD.Hide();
            }
            if (!_db.Rights["Client_Phone1"])
            {
              labelPhone1.Hide();
              textBoxPhone1.Hide();
            }
            if (!_db.Rights["Client_Phone2"])
            {
              labelPhone2.Hide();
              textBoxPhone2.Hide();
            }
            if (!_db.Rights["Client_Phone3"])
            {
              labelPhone3.Hide();
              textBoxPhone3.Hide();
            }
            if (!_db.Rights["Client_Adress"])
            {
              labelAdress.Hide();
              textBoxAdress.Hide();
            }
            if (!_db.Rights["Client_SO"])
            {
              labelSO.Hide();
              textBoxSO.Hide();
            }
            if (!_db.Rights["Client_Discount"])
            {
              labelDiscount.Hide();
              textBoxDiscount.Hide();
            }
            if (!_db.Rights["Client_FirmName"])
            {
              labelFirmName.Hide();
              textBoxFirmName.Hide();
            }

            ClientsBinding();

            foreach (DataColumn col in _db._ds.Tables["Client"].Columns)
            {
              string item = "";
              switch (col.ColumnName)
              {
            case "LastName":
              item = "Фамилия";
              break;
            case "FirstName":
              item = "Имя";
              break;
            case "MiddleName":
              item = "Отчество";
              break;
            case "Sex":
              item = "Пол";
              break;
            case "Phone1":
              item = "Телефон";
              break;
            case "Adress":
              item = "Адрес";
              break;
              }
              if (item != "")
            cbCritToFindClient.Items.Add(item);
            }

            //for Report

            DepsCB.DataSource = _db._ds.Tables["Department"];
            DepsCB.DisplayMember = "Name";
            DepsCB.ValueMember = "Id";

            //for Management

            dataGridViewRoles.DataSource = _db._ds.Tables["Position"];

            dataGridViewUsers.DataSource = _db._ds.Tables["User"];
              }
        }
Пример #4
0
        private void UserEditBtn_Click(object sender, EventArgs e)
        {
            User user = new User();

              if (dataGridViewUsers.CurrentRow != null)
              {
            user.SetValues(
              Convert.ToInt32(dataGridViewUsers.CurrentRow.Cells["Id"].Value),
              Convert.ToInt32(dataGridViewUsers.CurrentRow.Cells["PositionId"].Value),
              dataGridViewUsers.CurrentRow.Cells["Nick"].Value.ToString(),
              dataGridViewUsers.CurrentRow.Cells["Password"].Value.ToString()
              );

            UserForm pf = new UserForm(user, _db._ds.Tables["Position"], _db._ds.Tables["User"]);
            pf.ShowDialog();

            if (user.Id != 0)
            {
              _db._ds.Tables["User"].Rows[dataGridViewUsers.CurrentRow.Index]["Id"] = user.Id;
              _db._ds.Tables["User"].Rows[dataGridViewUsers.CurrentRow.Index]["PositionId"] = user.PositionId;
              _db._ds.Tables["User"].Rows[dataGridViewUsers.CurrentRow.Index]["Nick"] = user.Nick;
              _db._ds.Tables["User"].Rows[dataGridViewUsers.CurrentRow.Index]["Password"] = user.Password;

              _db._adapterUser.Update(_db._ds.Tables["User"]);
            }
              }
              else
              {
            MessageBox.Show(@"Выделите строку с пользователем!");
              }
        }
Пример #5
0
        private void NewUserBtn_Click(object sender, EventArgs e)
        {
            User user = new User();

              user.SetId(client.GetCurIdentity("User") + 1);

              UserForm uf = new UserForm(user, _db._ds.Tables["Position"], _db._ds.Tables["User"]);
              uf.ShowDialog();

              user = uf.user;

              if (user.Id != 0)
              {
            DataRow newRow = _db._ds.Tables["User"].NewRow();
            newRow["Id"] = user.Id;
            newRow["PositionId"] = user.PositionId;
            newRow["Nick"] = user.Nick;
            newRow["Password"] = user.Password;
            _db._ds.Tables["User"].Rows.Add(newRow);

            _db._adapterUser.Update(_db._ds.Tables["User"]);

            user.Clear();
              }
        }
Пример #6
0
        public void SetUser(User user)
        {
            DataRow row = _db._ds.Tables["User"].Rows.Find(user.Id);

              if (row == null)
              {
            row = _db._ds.Tables["User"].NewRow();

            row["Id"] = user.Id;
            row["Nick"] = user.Nick;
            row["Password"] = user.Password;
            row["PositionId"] = user.PositionId;

            _db._ds.Tables["User"].Rows.Add(row);
              }
              else
              {
            row["Id"] = user.Id;
            row["Nick"] = user.Nick;
            row["Password"] = user.Password;
            row["PositionId"] = user.PositionId;
              }

              _db._adapterUser.Update(_db._ds.Tables["User"]);

              OnDBChanged(_db);
        }