private void butSave_Click(object sender, EventArgs e) { try { SoundTimeConfig model = BuildModel(); int result = 0; if (idTimeConfig == 0) { result = soundTimeConfig.AddObj(model); } else { result = soundTimeConfig.UpdateObj(model); } if (result > 0) { MessageBox.Show("Lưu dữ liệu thành công."); LoadDataGridView(); idTimeConfig = 0; if (MessageBox.Show("Bạn có muốn khởi động lại chương trình?", "Khởi động chương trình", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Application.Restart(); } } else { MessageBox.Show("Lưu dữ liệu thất bại."); } } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message); } }
public List <SoundTimeConfig> GetListTimeByConfigType(int configType) { List <SoundTimeConfig> list = null; try { DataTable dt = LoadListTimeByConfigType(configType); if (dt != null && dt.Rows.Count > 0) { list = new List <SoundTimeConfig>(); foreach (DataRow row in dt.Rows) { SoundTimeConfig item = new SoundTimeConfig(); item.Time = TimeSpan.Parse(row["Time"].ToString()); item.SoLanDoc = int.Parse(row["SoLanDoc"].ToString()); list.Add(item); } } } catch (Exception ex) { throw ex; } return(list); }
public SoundTimeConfig BuildModel() { SoundTimeConfig model = null; try { model = new SoundTimeConfig(); TimeSpan time = new TimeSpan(0, 0, 0); try { DateTime datetime = DateTime.Parse(timeThoiGianDoc.EditValue.ToString()); time = datetime.TimeOfDay; } catch { TimeSpan.TryParse(timeThoiGianDoc.EditValue.ToString(), out time); } model.Time = TimeSpan.Parse(time.Hours.ToString() + ":" + time.Minutes.ToString() + ":00"); int soLanDoc = 1; int.TryParse(txtSoLanDoc.Text, out soLanDoc); model.SoLanDoc = soLanDoc; model.IsActive = chkIsActive.Checked; model.Id = idTimeConfig; // Cau hinh doc am thanh loi co configtype=2 model.ConfigType = 2; } catch (Exception ex) { throw ex; } return(model); }
public int UpdateObj(SoundTimeConfig obj) { int kq = 0; try { string sql = "update SOUND_TimeConfig set Time = '" + obj.Time + "', SoLanDoc=" + obj.SoLanDoc + ", IsActive='" + obj.IsActive + "', ConfigType=" + obj.ConfigType + " where Id =" + obj.Id + " and IsDeleted=0"; kq = dbclass.TruyVan_XuLy(sql); } catch (Exception ex) { throw ex; } return(kq); }
public int AddObj(SoundTimeConfig obj) { int kq = 0; try { string sql = "insert into SOUND_TimeConfig(Time, SoLanDoc, IsActive, ConfigType) values('" + obj.Time + "', " + obj.SoLanDoc + ", '" + obj.IsActive + "', " + obj.ConfigType + " )"; kq = dbclass.TruyVan_XuLy(sql); } catch (Exception ex) { throw ex; } return(kq); }