public EmployeeForm(Employee empl, int department, DataTable deps, DataTable roles, DataTable users, StoreServiceClient client) { InitializeComponent(); employee = empl; _department = department; _deps = deps; _roles = roles; _users = users; _client = client; }
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"]; } }
private void toolStripMenuItem5_Click(object sender, EventArgs e) { Employee employee = new Employee(); if (treeViewDepEmpl.SelectedNode != null) { DataRow dr = _db._ds.Tables["Employee"].Rows.Find(treeViewDepEmpl.SelectedNode.Name); employee.SetValues( Convert.ToInt32(dr["Id"]), dr["LastName"].ToString(), dr["FirstName"].ToString(), dr["MiddleName"].ToString(), Convert.ToInt32(dr["DepartmentId"]), Convert.ToInt32(dr["UserId"]), Convert.ToDateTime(dr["AcceptanceDate"]), Convert.ToDouble(dr["Bonuses"]), Convert.ToDouble(dr["SumOrders"]) ); EmployeeForm ef = new EmployeeForm( employee, employee.DepartmentId, _db._ds.Tables["Department"], _db._ds.Tables["Position"], _db._ds.Tables["User"], client ); ef.ShowDialog(); employee = ef.employee; if (employee.Id != 0) { client.SetEmployee(employee); //_waitForResponse.WaitOne(); } } }
private void newEmpToolStripMenuItem1_Click(object sender, EventArgs e) { int depNode; if (treeViewDepEmpl.Nodes.Count != 0) { if (treeViewDepEmpl.SelectedNode != null) { depNode = treeViewDepEmpl.SelectedNode.Index; } else { MessageBox.Show(@"Нужно выделить левой кнопкой отдел, в котором будете создавать работника!"); treeViewDepEmpl.Focus(); return; } } else { depNode = 0; } Employee employee = new Employee(); employee.SetId(client.GetCurIdentity("Employee") + 1); EmployeeForm ef = new EmployeeForm( employee, depNode, _db._ds.Tables["Department"], _db._ds.Tables["Position"], _db._ds.Tables["User"], client ); ef.ShowDialog(); employee = ef.employee; User user = ef.user; if (employee.Id != 0) { client.SetUser(user); //_waitForResponse.WaitOne(); client.SetEmployee(employee); //_waitForResponse.WaitOne(); } }
public void SetEmployee(Employee employee) { DataRow row = _db._ds.Tables["Employee"].Rows.Find(employee.Id); if (row == null) { row = _db._ds.Tables["Employee"].NewRow(); row["Id"] = employee.Id; row["FirstName"] = employee.FirstName; row["LastName"] = employee.LastName; row["MiddleName"] = employee.MiddleName; row["AcceptanceDate"] = employee.AcceptanceDate; row["Bonuses"] = employee.Bonuses; row["DepartmentId"] = employee.DepartmentId; row["SumOrders"] = employee.SumOrders; row["UserId"] = employee.UserId; _db._ds.Tables["Employee"].Rows.Add(row); } else { row["Id"] = employee.Id; row["FirstName"] = employee.FirstName; row["LastName"] = employee.LastName; row["MiddleName"] = employee.MiddleName; row["AcceptanceDate"] = employee.AcceptanceDate; row["Bonuses"] = employee.Bonuses; row["DepartmentId"] = employee.DepartmentId; row["SumOrders"] = employee.SumOrders; row["UserId"] = employee.UserId; } _db._adapterEmployee.Update(_db._ds.Tables["Employee"]); OnDBChanged(_db); }