예제 #1
0
        public bool them(LoaiBanThangDTO lbt)
        {
            string query = string.Empty;

            query += "INSERT INTO [loaibanthang] ([MaLoaiBT], [TenLoaiBT])";
            query += "VALUES (@MaLoaiBT,@TenLoaiBT)";
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@MaLoaiBT", lbt.MaLoaiBT);
                    cmd.Parameters.AddWithValue("@TenLoaiBT", lbt.TenLoaiBT);
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        con.Dispose();
                    }
                    catch (Exception ex)
                    {
                        con.Close();
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #2
0
        private void LBTRemoveButt_Click(object sender, EventArgs e)
        {
            string          dataID       = dataGridViewLBT.CurrentRow.Cells[0].Value.ToString();
            string          data         = dataGridViewLBT.CurrentRow.Cells[1].Value.ToString();
            LoaiBanThangDTO itemtoRemove = ListLoaiBanThangSTO.SingleOrDefault(item => item.MaLoaiBT == dataID);

            ListLoaiBanThangSTO.Remove(itemtoRemove);

            for (int i = 0; i < ListLoaiBanThangSTO.Count; i++) //set lại ID LBT cho List
            {
                ListLoaiBanThangSTO[i].MaLoaiBT = i.ToString();
            }
            dataGridViewLBT_load();
        }
예제 #3
0
        private void DefaultButt_Click(object sender, EventArgs e)
        {
            tsBUS.deleteData();
            lbtBUS.deleteData();
            LoaiBanThangDTO lbt = new LoaiBanThangDTO();

            lbt.MaLoaiBT  = "0";
            lbt.TenLoaiBT = "A";
            lbtBUS.them(lbt);
            LoaiBanThangDTO lbt1 = new LoaiBanThangDTO();

            lbt1.MaLoaiBT  = "1";
            lbt1.TenLoaiBT = "B";
            lbtBUS.them(lbt1);
            LoaiBanThangDTO lbt2 = new LoaiBanThangDTO();

            lbt2.MaLoaiBT  = "2";
            lbt2.TenLoaiBT = "C";
            lbtBUS.them(lbt2);
            UpdateButt_Clicked = 0;
            loadData();
        }
예제 #4
0
        private void formThemLBT_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (formThemLBT.AddStatus == true)
            {
                LoaiBanThangDTO lbt_DTO = new LoaiBanThangDTO();
                lbt_DTO.MaLoaiBT  = ListLoaiBanThangSTO.Count().ToString();
                lbt_DTO.TenLoaiBT = formThemLBT.send_data();
                ListLoaiBanThangSTO.Add(lbt_DTO);

                BindingSource bsLBT = new BindingSource();
                bsLBT.DataSource = ListLoaiBanThangSTO;
                dataGridViewLBT.Columns.Clear();
                dataGridViewLBT.DataSource           = null;
                dataGridViewLBT.ColumnHeadersVisible = false;

                dataGridViewLBT.AutoGenerateColumns = false;
                dataGridViewLBT.AllowUserToAddRows  = false;
                dataGridViewLBT.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                dataGridViewLBT.DataSource          = bsLBT;

                DataGridViewTextBoxColumn clMLBT = new DataGridViewTextBoxColumn();
                clMLBT.Name             = "MaLoaiCT";
                clMLBT.HeaderText       = "Mã Loại BT";
                clMLBT.DataPropertyName = "MaLoaiBT";
                dataGridViewLBT.Columns.Add(clMLBT);
                clMLBT.Visible = false;

                DataGridViewTextBoxColumn clLBT = new DataGridViewTextBoxColumn();
                clLBT.Name             = "LoaiBT";
                clLBT.HeaderText       = "Loại BT";
                clLBT.DataPropertyName = "TenLoaiBT";
                dataGridViewLBT.Columns.Add(clLBT);

                dataGridViewLBT.CurrentCell = dataGridViewLBT.Rows[0].Cells[1]; //thiết lập lại currentCell
            }

            formThemLBT = new ThemLoaiBT();
        }
        public bool them(LoaiBanThangDTO lbt)
        {
            bool re = lbtDAL.them(lbt);

            return(re);
        }