private void btnSubmit_Click(object sender, EventArgs e) { if (this.txtTypcod.Text.Length > 0) { CRUDResult post; if (this.mode == FORM_MODE.ADD) // Add { Console.WriteLine("current tabtyp = " + Istab.getTabtypString(this.tabtyp)); string json_data = "{\"tabtyp\":\"" + Istab.getTabtypString(this.tabtyp) + "\","; json_data += "\"typcod\":\"" + this.txtTypcod.Text.cleanString() + "\","; json_data += "\"abbreviate_en\":\"" + this.txtAbbreviate_en.Text.cleanString() + "\","; json_data += "\"abbreviate_th\":\"" + this.txtAbbreviate_th.Text.cleanString() + "\","; json_data += "\"typdes_en\":\"" + this.txtTypdes_en.Text.cleanString() + "\","; json_data += "\"typdes_th\":\"" + this.txtTypdes_th.Text.cleanString() + "\"}"; Console.WriteLine(json_data); post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/create", json_data); } else // Edit { string json_data = "{\"id\":" + this.istab.id.ToString() + ","; json_data += "\"tabtyp\":\"" + this.istab.tabtyp + "\","; json_data += "\"typcod\":\"" + this.istab.typcod + "\","; json_data += "\"abbreviate_en\":\"" + this.txtAbbreviate_en.Text.cleanString() + "\","; json_data += "\"abbreviate_th\":\"" + this.txtAbbreviate_th.Text.cleanString() + "\","; json_data += "\"typdes_en\":\"" + this.txtTypdes_en.Text.cleanString() + "\","; json_data += "\"typdes_th\":\"" + this.txtTypdes_th.Text.cleanString() + "\"}"; Console.WriteLine(json_data); post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/submit_change", json_data); } ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(post.data); Console.WriteLine(post.data); if (sr.result == ServerResult.SERVER_RESULT_SUCCESS) { if (sr.istab != null) { this.istab = sr.istab[0]; } this.DialogResult = DialogResult.OK; this.Close(); } else { MessageAlert.Show(sr.message, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR); } } else { MessageAlert.Show(StringResource.PLEASE_FILL_CODE, "Warning", MessageAlertButtons.OK, MessageAlertIcons.WARNING); this.txtTypcod.Focus(); } }
private void UpdateData() { this.FormProcessing(); Istab data = this.GetDataInForm(); bool post_success = false; string err_msg = ""; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += delegate { string json_data = "{\"id\":" + data.id.ToString() + ","; json_data += "\"tabtyp\":\"" + Istab.getTabtypString(this.tabtyp) + "\","; json_data += "\"typcod\":\"" + data.typcod.cleanString() + "\","; json_data += "\"abbreviate_th\":\"" + data.abbreviate_th.cleanString() + "\","; json_data += "\"abbreviate_en\":\"" + data.abbreviate_en.cleanString() + "\","; json_data += "\"typdes_th\":\"" + data.typdes_th.cleanString() + "\","; json_data += "\"typdes_en\":\"" + data.typdes_en.cleanString() + "\"}"; CRUDResult post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/submit_change", json_data); ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(post.data); if (sr.result == ServerResult.SERVER_RESULT_SUCCESS) { post_success = true; } else { post_success = false; err_msg = sr.message; } }; worker.RunWorkerCompleted += delegate { if (post_success) { this.GetIstabData(data); } else { MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR); this.FormEdit(); if (this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true).Length > 0) { ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true)[0]).textBox1.Focus(); } } }; worker.RunWorkerAsync(); }
private void btnGo_Click(object sender, EventArgs e) { this.tableLayoutPanel1.Visible = false; DateTime first_date = DateTime.Parse(this.year.ToString() + "-" + this.month.ToString() + "-1", CultureInfo.GetCultureInfo("th-TH")); int days_in_month = DateTime.DaysInMonth((this.year - 543), this.month); DateTime last_date = first_date.AddDays(days_in_month - 1); int first_day_of_week = first_date.GetDayIntOfWeek(); string from_date = DateTime.Parse(this.year.ToString() + "/" + this.month.ToString() + "/1", CultureInfo.GetCultureInfo("th-TH"), DateTimeStyles.None).ToMysqlDate(); string to_date = DateTime.Parse(this.year.ToString() + "/" + this.month.ToString() + "/" + days_in_month.ToString(), CultureInfo.GetCultureInfo("th-TH"), DateTimeStyles.None).ToMysqlDate(); List <EventCalendar> event_cal; List <TrainingCalendar> training_cal; List <NoteCalendar> note_cal; CRUDResult get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "eventcalendar/get_event&from_date=" + from_date + "&to_date=" + to_date); ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(get.data); if (sr.result == ServerResult.SERVER_RESULT_SUCCESS) { event_cal = sr.event_calendar; training_cal = sr.training_calendar; note_cal = sr.note_calendar; } else { event_cal = new List <EventCalendar>(); training_cal = new List <TrainingCalendar>(); note_cal = new List <NoteCalendar>(); } List <Istab> absent_cause = IstabWindow.GetIstab(Istab.getTabtypString(Istab.TABTYP.ABSENT_CAUSE)); List <Users> users_list = UsersList.GetUsers(); int increase_date = 0 + ((first_day_of_week - 1) * -1); for (int i = 1; i < this.tableLayoutPanel1.RowCount; i++) { for (int j = 0; j < this.tableLayoutPanel1.ColumnCount; j++) { // remove existing control if (this.tableLayoutPanel1.GetControlFromPosition(j, i) != null) { this.tableLayoutPanel1.Controls.Remove(this.tableLayoutPanel1.GetControlFromPosition(j, i)); } // create new control NoteCalendar note = note_cal.Where(n => n.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).FirstOrDefault(); int max_leave = note != null ? note.max_leave : -1; List <AbsentVM> absent_list = event_cal.Where(ev => ev.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).ToAbsentViewModel(absent_cause, users_list, max_leave); var trainer = training_cal.Where(t => t.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).ToList(); //var note = note_cal; CustomDateEvent2 de = new CustomDateEvent2(this.main_form, this, first_date.AddDays(increase_date), this.month, absent_list, absent_cause, trainer, note, users_list, max_leave); this.tableLayoutPanel1.Controls.Add(de, j, i); increase_date++; } } this.tableLayoutPanel1.Visible = true; }