Пример #1
0
 public int Ins(Configs aConfigs)
 {
     try {
         databaseDA.Configs.AddOrUpdate(aConfigs);
         return databaseDA.SaveChanges();
     }
     catch (Exception ex) {
         throw new Exception(String.Format("ConfigsBO.Ins: {0}", ex.Message));
     }
 }
 //=======================================================
 //Author: Hiennv
 //Function : Insert
 //=======================================================
 public int Insert(Configs aConfigs)
 {
     try
     {
         aDatabaseDA.Configs.Add(aConfigs);
         return aDatabaseDA.SaveChanges();
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("ConfigsBO.Insert :" + ex.Message));
     }
 }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                string accessKey = txtAccessKey.Text;
                string value = txtValue.Text;
                if (accessKey.Length > 250)
                {
                    txtAccessKey.Focus();
                    MessageBox.Show("AccessKey chỉ được phép nhập tối đa 250 ký tự .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (value.Length > 250)
                {
                    txtValue.Focus();
                    MessageBox.Show("Giá trị chỉ được phép nhập tối đa 250 ký tự .", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    ConfigsBO aConfigBO = new ConfigsBO();
                    Configs aConfigs = new Configs();
                    aConfigs.AccessKey = accessKey;
                    aConfigs.Value = value;
                    aConfigs.Status = cboStatus.SelectedIndex + 1;
                    aConfigs.Type = cboType.SelectedIndex + 1;
                    aConfigs.Group = (cboGroup.SelectedIndex + 1).ToString();
                    aConfigBO.Insert(aConfigs);
                    MessageBox.Show("Thêm mới thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                    if(this.afrmLst_Configs !=null)
                    {
                        this.afrmLst_Configs.LoadDataConfigs(AccessKey);
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmIns_Configs.btnAddNew_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         ConfigsBO aConfigsBO = new ConfigsBO();
         Configs aConfigs = new Configs();
         aConfigs.ID = ID;
         aConfigs.AccessKey = txtAccessKey.Text;
         aConfigs.Value = txtValue.Text;
         aConfigs.Status = cboStatus.SelectedIndex + 1;
         aConfigs.Type = cboType.SelectedIndex + 1;
         aConfigs.Group =  (cboGroup.SelectedIndex + 1).ToString();
         aConfigsBO.Update(aConfigs);
         MessageBox.Show("Cập nhật dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
         this.afrmLst_Configs.LoadDataConfigs(AccessKey);
     }
     catch(Exception ex)
     {
         MessageBox.Show("frmUpd_Configs.btnSave_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #5
0
        private void Ins(HttpContext context)
        {
            String jSonString = "";
            try {
                Configs aConfigs = new Configs {
                    AccessKey =
                        !String.IsNullOrEmpty(context.Request.Form["txtAccessKey"])
                            ? Convert.ToString(context.Request.Form["txtAccessKey"])
                            : "",
                    Value =
                        !String.IsNullOrEmpty(context.Request.Form["txtValue"])
                            ? Convert.ToString(context.Request.Form["txtValue"])
                            : "",
                    Status =
                        !String.IsNullOrEmpty(context.Request.Form["cbbStatus"])
                            ? Convert.ToInt32(context.Request.Form["cbbStatus"])
                            : 0,
                    Type =
                        !String.IsNullOrEmpty(context.Request.Form["cbbType"])
                            ? Convert.ToInt32(context.Request.Form["cbbType"])
                            : 0,
                    Group =
                        !String.IsNullOrEmpty(context.Request.Form["cbbGroup"])
                            ? Convert.ToInt32(context.Request.Form["cbbGroup"])
                            : 0,
                    Note =
                        !String.IsNullOrEmpty(context.Request.Form["txtNote"])
                            ? Convert.ToString(context.Request.Form["txtNote"])
                            : "",
                    Image =
                        !String.IsNullOrEmpty(context.Request.Form["txtImage_1"])
                            ? Convert.ToString(context.Request.Form["txtImage_1"])
                            : "",
                    Disable =
                        !String.IsNullOrEmpty(context.Request.Form["cbbDisable"])
                            ? Convert.ToBoolean(context.Request.Form["cbbDisable"])
                            : false,
                };

                ConfigsBO configsBO = new ConfigsBO();
                int ret = configsBO.Ins(aConfigs);

                if (ret != 0) jSonString = "{\"status\": \"success\"}";
                if (ret == 0) jSonString = "{\"status\":\"error|" + ret + "\"}";
            }
            catch (Exception ex) {
                jSonString = "{\"status\":\"error\" ,\"message\":\"" + ex.Message + "\"}";
            }
            finally {
                context.Response.Write(jSonString);
            }
        }