public static CompanyType GetCompanyType(int id) { CompanyType companyType = null; string sqlExpression = "SELECT * FROM CompanyType WHERE Id = @id AND Deleted = 0"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add("@id", SqlDbType.Int); command.Parameters["@id"].Value = id; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string name = (string)reader["Name"]; companyType = new CompanyType(name) { Id = id }; } } } return(companyType); }
public static List <CompanyType> GetAllCompanyTypes() { List <CompanyType> companyTypes = new List <CompanyType>(); string sqlExpression = "SELECT * FROM CompanyType WHERE Deleted = 0"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int id = (int)reader["Id"]; string name = (string)reader["Name"]; CompanyType companyType = new CompanyType(name) { Id = id }; companyTypes.Add(companyType); } } } return(companyTypes); }
public Company(Director director, CompanyType type, Chancery companyChancery, string name, string address) { Director = director; Chancery = companyChancery; Type = type; Name = name; Address = address; }
public override bool Equals(object obj) { if (obj == null || obj == DBNull.Value) { return(false); } CompanyType companyType = (CompanyType)obj; if (companyType.Id <= 0 || Id <= 0) { return(false); } return(Id == companyType.Id); }
public static void UpdateCompanyType(CompanyType companyType) { string sqlExpression = "UPDATE CompanyType SET Name = @name WHERE Id = @id"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add("@name", SqlDbType.VarChar); command.Parameters.Add("@id", SqlDbType.Int); command.Parameters["@name"].Value = companyType.type; command.Parameters["@id"].Value = companyType.Id; command.ExecuteNonQuery(); } }
public static void AddCompanyType(CompanyType companyType) { string sqlExpression = "INSERT INTO CompanyType(Id, Name) VALUES (@id, @name)"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add("@id", SqlDbType.Int); command.Parameters.Add("@name", SqlDbType.Text); command.Parameters["@id"].Value = companyType.Id; command.Parameters["@name"].Value = companyType.type; command.ExecuteNonQuery(); } }
public static Company GetCompany(int id) { Company company = null; string sqlExpression = "SELECT * FROM Company WHERE Id = @id AND Deleted = 0"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = new SqlCommand(sqlExpression, connection); command.Parameters.Add("@id", SqlDbType.Int); command.Parameters["@id"].Value = id; SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int companyTypeId = (int)reader["CompanyTypeId"]; string name = (string)reader["CompanyName"]; string address = (string)reader["CompanyAddress"]; Director director = new Director() { InitState = InitializationState.INITIALIZATION_NEEDED }; Chancery chancery = new Chancery() { InitState = InitializationState.INITIALIZATION_NEEDED }; CompanyType companyType = SqlCompanyType.GetCompanyType(companyTypeId); company = new Company(director, companyType, chancery, name, address) { Id = id }; } } } return(company); }
public static List <Company> GetAllCompanies() { List <Company> companies = new List <Company>(); string sqlExpression = "SELECT * FROM Company WHERE Deleted = 0"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand expression = new SqlCommand(sqlExpression, connection); SqlDataReader reader = expression.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int id = (int)reader["Id"]; int companyTypeId = (int)reader["CompanyTypeId"]; string name = (string)reader["CompanyName"]; string address = (string)reader["CompanyAddress"]; Director director = new Director() { InitState = InitializationState.INITIALIZATION_NEEDED }; Chancery chancery = new Chancery() { InitState = InitializationState.INITIALIZATION_NEEDED }; CompanyType companyType = SqlCompanyType.GetCompanyType(companyTypeId); Company company = new Company(director, companyType, chancery, name, address) { Id = id }; companies.Add(company); } } } return(companies); }
private void AddCompanyButton_Click(object sender, EventArgs e) { bool filled = Utils.CheckFormFilled(this); if (filled && director != null) { String name = Utils.FindControl(this, "nameBox").Text; String address = Utils.FindControl(this, "addressBox").Text; CompanyType type = (CompanyType)((ComboBox)Utils.FindControl(this, "typeBox")).SelectedValue; bool nameValidated = CompanyFormValidator.ValidateName(name); bool addressValidated = CompanyFormValidator.ValidateAddress(address); if (nameValidated && addressValidated) { Chancery chancery = new Chancery { Archive = new List <Document>(), PendingDocuments = new List <Document>(), Secretaries = new List <Secretary>() }; Company company = new Company(director, type, chancery, name, address); company.Persist(); DocumentManagementForm form = (DocumentManagementForm)Application.OpenForms["DocumentManagementForm"]; form.UpdateCompaniesBox(); Close(); Dispose(); } else { MessageBox.Show("Неправильно введенные данные!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Одно из полей пустое!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void CommitEditEvent(object sender, EventArgs e) { bool filled = true; bool correct = true; foreach (Control c in Controls) { if (c is TextBox) { if (string.IsNullOrWhiteSpace(c.Text) || director == null) { MessageBox.Show("Одно из полей пустое!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); filled = false; break; } } } if (filled) { Control nameBox = Utils.FindControl(this, "nameBox"); Control addressBox = Utils.FindControl(this, "addressBox"); Control personsBox = Utils.FindControl(this, "personsBox"); Control typeBox = Utils.FindControl(this, "typeBox"); Control directorBox = Utils.FindControl(this, "directorBox"); Control directorChooserButton = Utils.FindControl(this, "directorChooserButton"); Button openChanceryButton = (Button)Utils.FindControl(this, "openChanceryButton"); try { if (directorChanged) { //Удаляем старого директора company.Director.Delete(); company.Director = null; //Добавляем нового директора director.Persist(); company.Director = director; } //Обновляем компанию string name = nameBox.Text; string address = addressBox.Text; CompanyType type = (CompanyType)((ComboBox)typeBox).SelectedItem; company.Name = name; company.Address = address; company.Type = type; DocumentManagementForm form = (DocumentManagementForm)Application.OpenForms["DocumentManagementForm"]; form.UpdateCompaniesBox(); } catch (Exception ex) { MessageBox.Show("Неправильно введенные данные!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); correct = false; } if (correct) { Controls.Remove(nameBox); Controls.Remove(addressBox); Controls.Remove(typeBox); Controls.Remove(personsBox); Controls.Remove(directorBox); Controls.Remove(directorChooserButton); Controls.Remove((Control)sender); openChanceryButton.Enabled = true; directorChanged = false; AddInfoForms(); } } }