private void HoursAdd_Load(object sender, EventArgs e) { Contractors curForm = (Contractors)this.Owner; txt_HA_CCode.Text = curForm.GetCCode(); txt_HA_Name.Text = curForm.GetCName(); txt_HA_Surname.Text = curForm.GetCSurname(); txt_HA_EName.Text = curForm.GetEName(); send = curForm.GetSender(); dt = curForm.GetHours(); if (send is Button) { btn_HA_CreateRem.Visible = false; txt_HA_ExcRate.Text = "0.00000"; txt_HA_ExcRate.SelectionStart = txt_HA_ExcRate.Text.Length; txt_HA_DolPH.Text = "$0.00"; txt_HA_DolPH.SelectionStart = txt_HA_DolPH.Text.Length; txt_HA_TotBE.Text = "$0.00"; txt_HA_TotBE.SelectionStart = txt_HA_TotBE.Text.Length; txt_HA_QTCut.Text = "R0.00"; txt_HA_QTCut.SelectionStart = txt_HA_QTCut.Text.Length; txt_HA_TotAE.Text = "R0.00"; txt_HA_TotAE.SelectionStart = txt_HA_TotAE.Text.Length; txt_HA_FTotal.Text = "R0.00"; txt_HA_FTotal.SelectionStart = txt_HA_FTotal.Text.Length; dtp_HA_From.Value = DateTime.Now; dtp_HA_To.Value = dtp_HA_From.Value.AddDays(6); dtp_HA_DatePaid.Value = DateTime.Now; int newCode = 0; foreach (DataRow dr in dt.Rows) { if (dr.RowState == DataRowState.Deleted) { string str = dr["Code", DataRowVersion.Original].ToString().Trim(); int pos = str.IndexOf("_"); int x = Convert.ToInt32(str.Remove(0, pos + 2)); if (x > newCode) { newCode = x; } } else { string str = dr["Code"].ToString().Trim(); int pos = str.IndexOf("_"); int x = Convert.ToInt32(str.Remove(0, pos + 2)); if (x > newCode) { newCode = x; } } } newCode++; txt_HA_Code.Text = txt_HA_CCode.Text.Split('_')[1] + "_" + newCode.ToString("0000"); } else { Text = "Edit Work Week"; SELECTED_WW = curForm.GetSelectedHour(); LoadHours(); } }