public WorkPermit Clone() { WorkPermit newWp = new WorkPermit(); newWp.Date = this.Date; newWp.HourFrom = this.HourFrom; newWp.HourTo = this.HourTo; newWp.Number = this.Number; newWp.Place = this.Place; newWp.Type = this.Type; newWp.WorkPermitId = this.WorkPermitId; newWp.Department = this.Department; newWp.Description = this.Description; newWp.CompanyName = this.CompanyName; newWp.CompanyPhone = this.CompanyPhone; newWp.Applicant = this.Applicant; newWp.Authorizing = this.Authorizing; newWp.AuthorizingPPN = this.AuthorizingPPN; newWp.AuthorizingPZ = this.AuthorizingPZ; newWp.AuthorizingPNW = this.AuthorizingPNW; newWp.ControllerPPN = this.ControllerPPN; newWp.Holder = this.Holder; newWp.Users = this.Users; newWp.CheckKeeper = new WorkPermitCheckKeeper(); newWp.CheckKeeper = this.CheckKeeper.CloneJson <WorkPermitCheckKeeper>(); return(newWp); }
private void bringWorkPermit(object sender, DataGridViewCellEventArgs e) { int wpId = Convert.ToInt32(dgWorkPermits.Rows[dgWorkPermits.CurrentCell.RowIndex].Cells[0].Value); WorkPermit wp = Keeper.WorkPermits.Where(i => i.WorkPermitId == wpId).FirstOrDefault(); dataFiller df = new dataFiller(Keeper, wpId); df.Show(); }
public dataFiller(WorkPermitKeeper keeper, int wpId = 0, bool copy = false) { InitializeComponent(); wp = new WorkPermit(wpId); Keeper = keeper; if (wp.WorkPermitId == 0) { this.Text = "Nowe pozwolenie"; txtNumber.Text = wp.Number; createAutoComplete(); this.Controls.Add(ACKeeper.Output); } else { this.Text = "Edycja pozwolenia"; txtNumber.Text = wp.Number; txtDescription.Text = wp.Description; txtDepartment.Text = wp.Department; txtPlace.Text = wp.Place; txtCompany.Text = wp.CompanyName; txtPhone.Text = wp.CompanyPhone; txtApplicant.Text = wp.Applicant; txtHolder.Text = wp.Holder; dtDate.Value = wp.Date; txtUsers.Text = wp.GetUsers(); txtAuthorizing.Text = wp.Authorizing; txtAuthorizingPPN.Text = wp.AuthorizingPPN; txtAuthorizingPZ.Text = wp.AuthorizingPZ; txtAuthorizingPNW.Text = wp.AuthorizingPNW; txtControllerPPN.Text = wp.ControllerPPN; cmbFrom.Text = wp.HourFrom; cmbTo.Text = wp.HourTo; if (copy) { this.Text = "Nowe pozwolenie"; wp.Type = 1; wp.WorkPermitId = 0; wp.Date = DateTime.Now.Date; dtDate.ResetText(); cmbFrom.ResetText(); cmbFrom.SelectedIndex = -1; cmbTo.ResetText(); cmbTo.SelectedIndex = -1; wp.getNewNumber(); txtNumber.Text = wp.Number; createAutoComplete(); this.Controls.Add(ACKeeper.Output); } } }
public void Download() { WorkPermits.Clear(); string sql = "SELECT * FROM tbWorkPermits ORDER BY date DESC;"; try { using (SqlConnection conn = new SqlConnection(Variables.npdConnectionString)) { conn.Open(); SqlCommand sqlComand; sqlComand = new SqlCommand(sql, conn); using (SqlDataReader reader = sqlComand.ExecuteReader()) { while (reader.Read()) { WorkPermit wp = new WorkPermit { WorkPermitId = reader.GetInt32(reader.GetOrdinal("workPermitId")), Date = reader.GetDateTime(reader.GetOrdinal("date")), Number = reader["number"].ToString(), HourFrom = reader["hourFrom"].ToString(), HourTo = reader["hourTo"].ToString(), Description = reader["description"].ToString(), Department = reader["department"].ToString(), Place = reader["place"].ToString(), CompanyName = reader["company"].ToString(), CompanyPhone = reader["companyPhone"].ToString(), Applicant = reader["applicant"].ToString(), Holder = reader["holder"].ToString(), Authorizing = reader["authorizing"].ToString(), AuthorizingPPN = reader["authorizingPPN"].ToString(), AuthorizingPZ = reader["authorizingPZ"].ToString(), AuthorizingPNW = reader["authorizingPNW"].ToString(), ControllerPPN = reader["controllerPPN"].ToString(), DateAdded = reader.GetDateTime(reader.GetOrdinal("dateAdded")), Users = reader["users"].ToString().Split(',').ToList() }; WorkPermits.Add(wp); } } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); //MessageBox.Show(String.Format("Nie udało się nawiązać połączenia z bazą danych", "Błąd połączenia z bazą danych")); } }
public WorkPermit(int Id = 0) { this.WorkPermitId = Id; if (Id == 0) { this.Date = DateTime.Now.Date; this.Type = 1; CheckKeeper = new WorkPermitCheckKeeper(); getNewNumber(); } else { this.Type = 2; BringDetails(); BringChecks(); } initialState = this.Clone(); InitialChecks = this.CheckKeeper.CloneJson <WorkPermitCheckKeeper>(); }
public frmP1(WorkPermit wp) { thisPermit = wp; InitializeComponent(); }
public void Save() { if (Validate()) { string sql = ""; if (this.Type == 1) { sql = @"INSERT INTO tbWorkPermits (number, date, hourFrom, hourTo, description, department, place, company, companyPhone, applicant, holder, users, authorizing, authorizingPPN, authorizingPZ, authorizingPNW, controllerPPN, dateAdded) output INSERTED.WorkPermitId VALUES (@number, @date, @hourFrom, @hourTo, @description, @department, @place, @company, @companyPhone, @applicant, @holder, @users, @authorizing, @authorizingPPN, @authorizingPZ, @authorizingPNW, @controllerPPN, @dateAdded)"; } else if (this.Type == 2) { sql = @"UPDATE tbWorkPermits SET number=@number, date=@date, hourFrom=@hourFrom, hourTo=@hourTo, description=@description, department=@department, place=@place, company=@company, companyPhone=@companyPhone, applicant=@applicant, holder=@holder, users=@users, authorizing=@authorizing, authorizingPPN=@authorizingPPN, authorizingPZ=@authorizingPZ, authorizingPNW=@authorizingPNW, controllerPPN=@controllerPPN WHERE workPermitId=@id"; } try { using (SqlConnection conn = new SqlConnection(Variables.npdConnectionString)) { SqlCommand sqlComand; using (sqlComand = new SqlCommand(sql, conn)) { sqlComand.Parameters.AddWithValue("@number", this.Number); sqlComand.Parameters.AddWithValue("@date", this.Date.ToString()); sqlComand.Parameters.AddWithValue("@hourFrom", this.HourFrom); sqlComand.Parameters.AddWithValue("@hourTo", this.HourTo); sqlComand.Parameters.AddWithValue("@description", this.Description); sqlComand.Parameters.AddWithValue("@department", this.Department); sqlComand.Parameters.AddWithValue("@place", this.Place); sqlComand.Parameters.AddWithValue("@company", this.CompanyName); sqlComand.Parameters.AddWithValue("@companyPhone", this.CompanyPhone); sqlComand.Parameters.AddWithValue("@applicant", this.Applicant); sqlComand.Parameters.AddWithValue("@holder", this.Holder); sqlComand.Parameters.AddWithValue("@users", this.GetUsers()); sqlComand.Parameters.AddWithValue("@authorizing", this.Authorizing); sqlComand.Parameters.AddWithValue("@authorizingPPN", this.AuthorizingPPN); sqlComand.Parameters.AddWithValue("@authorizingPZ", this.AuthorizingPZ); sqlComand.Parameters.AddWithValue("@authorizingPNW", this.AuthorizingPNW); sqlComand.Parameters.AddWithValue("@controllerPPN", this.ControllerPPN); if (this.Type == 1) { sqlComand.Parameters.AddWithValue("@dateAdded", DateTime.Now); conn.Open(); this.WorkPermitId = (int)sqlComand.ExecuteScalar(); } else { sqlComand.Parameters.AddWithValue("@id", this.WorkPermitId); conn.Open(); sqlComand.ExecuteNonQuery(); } } } SaveChecks(); MessageBox.Show("Zapis zakończony powodzeniem!"); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } finally { initialState = this.Clone(); InitialChecks = initialState.CheckKeeper; } } }