Esempio n. 1
0
        public int AddObj(SoundReadConfig obj)
        {
            int kq = 0;

            try
            {
                string sql = "insert into SOUND_ReadConfig(Name, Description, IsActive, IdChuyen, ConfigType) values(N'" + obj.Name + "', N'" + obj.Description + "','" + obj.IsActive + "', " + obj.IdChuyen + ", " + obj.ConfigType + " )";
                var    resultAddReadConfig = dbclass.TruyVan_XuLy(sql);
                if (resultAddReadConfig != 0)
                {
                    if (obj.listItem.Count > 0)
                    {
                        string    sqlSel = "select top 1 Id from SOUND_ReadConfig order by Id desc";
                        DataTable dt     = dbclass.TruyVan_TraVe_DataTable(sqlSel);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            string Id = dt.Rows[0]["Id"].ToString();
                            foreach (SoundReadItem item in obj.listItem)
                            {
                                string sqlInsert = "insert into SOUND_ReadConfigDetail(IdReadConfig, OrderIndex, IntType, IdSound, IdIntConfig, IsActive) values(" + Id + ", " + item.OrderIndex + ", " + item.IntType + "," + item.IsSound + "," + item.IdIntConfig + ", '" + item.IsActive + "')";
                                dbclass.TruyVan_XuLy(sqlInsert);
                            }
                        }
                    }
                }
                kq = 1;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(kq);
        }
Esempio n. 2
0
 private void butSave_Click(object sender, EventArgs e)
 {
     try
     {
         SoundReadConfig model = BuildModel();
         if (model != null)
         {
             int result = 0;
             if (model.Id == 0)
             {
                 result = soundReadConfigDAO.AddObj(model);
             }
             else
             {
                 result = soundReadConfigDAO.UpdateObj(model);
             }
             if (result > 0)
             {
                 MessageBox.Show("Lưu dữ liệu thành công.");
                 this.sender();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Lưu dữ liệu thất bại.");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
Esempio n. 3
0
        public SoundReadConfig BuildModel()
        {
            SoundReadConfig model = null;

            try
            {
                if (string.IsNullOrEmpty(txtName.Text))
                {
                    MessageBox.Show("Lỗi: Tên cấu hình không được để trống");
                }
                else
                {
                    model             = new SoundReadConfig();
                    model.Id          = idReadNSConfig;
                    model.Name        = txtName.Text;
                    model.Description = txtDescription.Text;
                    model.IsActive    = chkIsActive.Checked;
                    model.IdChuyen    = idChuyen;
                    model.ConfigType  = configType;

                    if (dgListItem.Rows != null && dgListItem.Rows.Count > 0)
                    {
                        foreach (DataGridViewRow row in dgListItem.Rows)
                        {
                            SoundReadItem item = new SoundReadItem();
                            item.IntType = int.Parse(row.Cells["IndexTypeSelect"].Value.ToString());
                            if (item.IntType == 0)
                            {
                                item.IdIntConfig = int.Parse(row.Cells["IdObj"].Value.ToString());
                            }
                            else
                            {
                                item.IsSound = int.Parse(row.Cells["IdObj"].Value.ToString());
                            }
                            item.OrderIndex = int.Parse(row.Cells["ThuTuDoc"].Value.ToString());
                            item.IsActive   = bool.Parse(row.Cells["IsActiveOfDetail"].Value.ToString());
                            model.listItem.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
Esempio n. 4
0
        public SoundReadConfig GetInfoById(int Id)
        {
            SoundReadConfig config = null;

            try
            {
                string    sqlSelectConfig = "select * from SOUND_ReadConfig where Id=" + Id + " and IsDeleted=0;";
                DataTable dt = dbclass.TruyVan_TraVe_DataTable(sqlSelectConfig);
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataRow row = dt.Rows[0];
                    config             = new SoundReadConfig();
                    config.Id          = int.Parse(row["Id"].ToString());
                    config.Name        = row["Name"].ToString();
                    config.Description = row["Description"].ToString();
                    bool isActive = false;
                    bool.TryParse(row["IsActive"].ToString(), out isActive);
                    config.IsActive = isActive;
                    string    sqlSelectListItem = "select * from SOUND_ReadConfigDetail where IdReadConfig=" + config.Id + " and IsDeleted=0";
                    DataTable dtList            = dbclass.TruyVan_TraVe_DataTable(sqlSelectListItem);
                    if (dtList != null && dtList.Rows.Count > 0)
                    {
                        foreach (DataRow rowItem in dtList.Rows)
                        {
                            SoundReadItem item = new SoundReadItem();
                            item.IntType     = int.Parse(rowItem["IntType"].ToString());
                            item.OrderIndex  = int.Parse(rowItem["OrderIndex"].ToString());
                            item.IsSound     = int.Parse(rowItem["IdSound"].ToString());
                            item.IdIntConfig = int.Parse(rowItem["IdIntConfig"].ToString());
                            bool isActiveItem = false;
                            bool.TryParse(rowItem["IsActive"].ToString(), out isActiveItem);
                            item.IsActive = isActiveItem;
                            config.listItem.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(config);
        }
Esempio n. 5
0
        public int UpdateObj(SoundReadConfig obj)
        {
            int kq = 0;

            try
            {
                string sql = "update SOUND_ReadConfig set Name=N'" + obj.Name + "', Description =N'" + obj.Description + "', IsActive='" + obj.IsActive + "', ConfigType=" + obj.ConfigType + " where Id=" + obj.Id;
                var    resultAddReadConfig = dbclass.TruyVan_XuLy(sql);
                if (resultAddReadConfig != 0)
                {
                    string    sqlListItemOld = "select Id from SOUND_ReadConfigDetail where IsDeleted=0 and IdReadConfig=" + obj.Id;
                    DataTable dtListItemOld  = dbclass.TruyVan_TraVe_DataTable(sqlListItemOld);
                    if (dtListItemOld != null && dtListItemOld.Rows.Count > 0)
                    {
                        foreach (DataRow row in dtListItemOld.Rows)
                        {
                            string sqlDelete = "update SOUND_ReadConfigDetail set IsDeleted=1 where Id = " + row["Id"].ToString();
                            dbclass.TruyVan_XuLy(sqlDelete);
                        }
                    }
                    if (obj.listItem.Count > 0)
                    {
                        foreach (SoundReadItem item in obj.listItem)
                        {
                            string sqlInsert = "insert into SOUND_ReadConfigDetail(IdReadConfig, OrderIndex, IntType, IdSound, IdIntConfig, IsActive) values(" + obj.Id + ", " + item.OrderIndex + ", " + item.IntType + "," + item.IsSound + "," + item.IdIntConfig + ", '" + item.IsActive + "')";
                            dbclass.TruyVan_XuLy(sqlInsert);
                        }
                    }
                }
                kq = 1;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(kq);
        }
Esempio n. 6
0
        private void LoadInfoUpdate()
        {
            try
            {
                if (idReadNSConfig > 0)
                {
                    SoundReadConfig model = soundReadConfigDAO.GetInfoById(idReadNSConfig);
                    if (model != null)
                    {
                        txtName.Text        = model.Name;
                        txtDescription.Text = model.Description;
                        chkIsActive.Checked = model.IsActive;
                        if (model.listItem != null && model.listItem.Count > 0)
                        {
                            foreach (SoundReadItem item in model.listItem)
                            {
                                DataGridViewRow drow = new DataGridViewRow();

                                DataGridViewCell cell = new DataGridViewTextBoxCell();
                                cell.Value = item.IntType;
                                drow.Cells.Add(cell);

                                cell = new DataGridViewTextBoxCell();
                                if (item.IntType == 0)
                                {
                                    cell.Value = "Đọc số";
                                }
                                else
                                {
                                    cell.Value = "Đọc âm thanh";
                                }
                                drow.Cells.Add(cell);

                                ModelSelect modelSelect = null;
                                if (item.IntType == 0)
                                {
                                    cell       = new DataGridViewTextBoxCell();
                                    cell.Value = item.IdIntConfig;
                                    drow.Cells.Add(cell);

                                    cell = new DataGridViewTextBoxCell();
                                    if (cbbIntConfig.Items != null && cbbIntConfig.Items.Count > 0)
                                    {
                                        foreach (ModelSelect sl in cbbIntConfig.Items)
                                        {
                                            if (sl.Value == item.IdIntConfig)
                                            {
                                                cell.Value = sl.Text;
                                                break;
                                            }
                                        }
                                    }
                                    drow.Cells.Add(cell);
                                }
                                else
                                {
                                    cell       = new DataGridViewTextBoxCell();
                                    cell.Value = item.IsSound;
                                    drow.Cells.Add(cell);

                                    cell = new DataGridViewTextBoxCell();
                                    if (cbbSound.Items != null && cbbSound.Items.Count > 0)
                                    {
                                        foreach (ModelSelect sl in cbbSound.Items)
                                        {
                                            if (sl.Value == item.IsSound)
                                            {
                                                cell.Value = sl.Text;
                                                break;
                                            }
                                        }
                                    }
                                    drow.Cells.Add(cell);
                                }

                                cell       = new DataGridViewTextBoxCell();
                                cell.Value = item.OrderIndex;
                                drow.Cells.Add(cell);

                                cell       = new DataGridViewTextBoxCell();
                                cell.Value = item.IsActive;
                                drow.Cells.Add(cell);

                                dgListItem.Rows.Add(drow);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }