当前位置: 首页>>代码示例>>C#>>正文


C# DatabaseHelper类代码示例

本文整理汇总了C#中DatabaseHelper的典型用法代码示例。如果您正苦于以下问题:C# DatabaseHelper类的具体用法?C# DatabaseHelper怎么用?C# DatabaseHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DatabaseHelper类属于命名空间,在下文中一共展示了DatabaseHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Insert

        public int Insert(DatabaseHelper help)
        {
            // insert

            {
                try
                {
                    var t = new The_kho //Make sure you have a table called test in DB
                    {

                        Ma_vat_tu = this.Ma_vat_tu,                   // ID = Guid.NewGuid(),
                        Id_chat_luong = this.ID_chat_luong,
                        Don_vi = this.Don_vi,
                        Dia_diem = this.Dia_diem,

                    };

                    help.ent.The_kho.Add(t);
                    help.ent.SaveChanges();
                    return 1;
                }
                catch (Exception ex)
                {

                    return 0;

                }

            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:30,代码来源:clsTheKho.cs

示例2: GetAll

        //  SqlConnection m_dbConnection = new SqlConnection(clsThamSoUtilities.connectionString);
        public DataTable GetAll(string name, string mavattu, string tenvattu, string TenChatLuong)
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {
                var dm = (from d in help.ent.Vat_Tu_Goi_Dau_Ky
                          join e in help.ent.DM_Vat_Tu on d.Ma_vat_tu equals e.Ma_vat_tu
                          join f in help.ent.DM_Kho on d.ID_kho equals f.ID_kho
                          join gl in help.ent.Chat_luong on d.ID_chat_luong equals gl.Id_chat_luong

                          where gl.Loai_chat_luong.Contains(TenChatLuong) && f.Ten_kho.Contains(name)&& e.Ten_vat_tu .Contains(tenvattu)
                          && e.Ma_vat_tu.Contains(mavattu)
                          group d by new { d.Ma_vat_tu, e.Ten_vat_tu , f.Ten_kho,gl.Loai_chat_luong} into gs
                          let TotalPoints = gs.Sum(m => m.So_Luong)
                          orderby TotalPoints descending

                          select new
                          {
                              ten_kho = gs.Key.Ten_kho,

                              Chat_luong = gs.Key.Loai_chat_luong,

                              Ma_vat_tu = gs.Key.Ma_vat_tu,
                              ten_vat_tu = gs.Key.Ten_vat_tu,
                              so_luong = TotalPoints
                          }).ToList();
                dbcxtransaction.Commit();
                return Utilities.clsThamSoUtilities.ToDataTable(dm);
            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:32,代码来源:clsTonDauKy.cs

示例3: Insert

        public int Insert()
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            // insert
            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {
                try
                {
                    var t = new User //Make sure you have a table called test in DB
                    {
                        User_name = this.User_name,
                        Password = this.Password,                   // ID = Guid.NewGuid(),
                    };

                    help.ent.Users.Add(t);
                    help.ent.SaveChanges();
                    dbcxtransaction.Commit();
                    return 1;
                }
                catch (Exception ex)
                {
                    dbcxtransaction.Rollback();
                    return 0;

                }
            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:28,代码来源:clsUser.cs

示例4: Checkduplicaterows

        // End GetAll
        /// <summary>
        /// Kiểm tra trùng lập trước khi ADD
        /// </summary>
        /// <returns></returns>
        public bool Checkduplicaterows()
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            bool has = help.ent.DM_Vat_Tu.Any(cus => cus.Ma_vat_tu == Ma_vat_tu);
            return has;
            ////Mở
            //m_dbConnection.Open();
            //DataTable dt = new DataTable();

            ////Chuẩn bị
            //string sql = "";
            //sql += "SELECT * FROM DM_Vat_Tu ";
            //sql += "WHERE [email protected]_vat_tu";

            //SqlCommand command = new SqlCommand(sql, m_dbConnection);

            //command.Parameters.Add("@Ma_vat_tu", SqlDbType.Int).Value = Ma_vat_tu;

            //command.CommandType = CommandType.Text;

            ////Run
            //SqlDataAdapter da = new SqlDataAdapter(command);
            //da.Fill(dt);

            ////Đóng
            //m_dbConnection.Close();

            //if (dt.Rows.Count > 0)
            //{
            //    return true;
            //}
            //return false;
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:39,代码来源:clsDMVatTu.cs

示例5: getAll

        /// <summary>
        /// hàm tìm kiếm vật tư theo kho và chất lượng
        /// </summary>
        /// <param name="_ID_kho"></param>
        /// <returns></returns>
        public static DataTable getAll(string TenKho, string TenChatLuong,string tenvt, string mavt)
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {
                var dm = (from d in help.ent.Ton_kho
                          join e in help.ent.DM_Vat_Tu on d.Ma_vat_tu equals e.Ma_vat_tu
                          join f in help.ent.DM_Kho on d.ID_kho equals f.ID_kho
                          join gl in help.ent.Chat_luong on d.Id_chat_luong equals gl.Id_chat_luong

                          where gl.Loai_chat_luong.Contains(TenChatLuong) && f.Ten_kho.Contains(TenKho)&& e.Ten_vat_tu .Contains(tenvt)
                          && e.Ma_vat_tu.Contains(mavt)  && (f.isKhoNgoai == false || f.isKhoNgoai ==null)
                          group d by new { d.Ma_vat_tu, e.Ten_vat_tu } into gs
                          let TotalPoints = gs.Sum(m => m.So_luong)
                          orderby TotalPoints descending

                          select new
                          {

                              Ma_vat_tu = gs.Key.Ma_vat_tu,
                              ten_vat_tu = gs.Key.Ten_vat_tu,
                              so_luong = TotalPoints
                          }).ToList();
                dbcxtransaction.Commit();
                return Utilities.clsThamSoUtilities.ToDataTable(dm);
            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:33,代码来源:clsTonKho.cs

示例6: Update

        public int Update()
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            int temp = 0;
            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {
                Vat_Tu_Goi_Dau_Ky vtgd = new Vat_Tu_Goi_Dau_Ky();
                vtgd.ID_kho = this.ID_kho;
                vtgd.ID_chat_luong= this.ID_chat_luong;
                vtgd.Ma_vat_tu = this.Ma_vat_tu;
                vtgd.ID_VT_Goi_Dau = this.ID_VT_Goi_Dau;
                vtgd.So_Luong = this.So_Luong;
                using (var context = help.ent)
                {
                    context.Vat_Tu_Goi_Dau_Ky.Attach(vtgd);
                    context.Entry(vtgd).State = EntityState.Modified;
                    temp = help.ent.SaveChanges();
                    dbcxtransaction.Commit();

                }

            }
            return temp;
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:25,代码来源:clsVatTuGoiDauKy.cs

示例7: GetAll

        public static DataTable GetAll(string name)
        {
            DatabaseHelper help = new DatabaseHelper();
              help.ConnectDatabase();
              using (var dbcxtransaction = help.ent.Database.BeginTransaction())
              {
              var dm = (from d in help.ent.Kho_muon_vat_tu
                        join k in help.ent.DM_Kho on d.ID_Kho equals k.ID_kho
                        join c in help.ent.Chat_luong on d.Id_chat_luong equals c.Id_chat_luong
                        join v in help.ent.DM_Vat_Tu on d.Ma_vat_tu equals v.Ma_vat_tu

                        where k.Ten_kho .Contains(name) &&d.Da_tra == false

                        select new {
                        ID_kho_muon_vat_tu = d.ID_kho_muon_vat_tu,
                        ID_kho = d.ID_Kho,
                        ID_Kho_Muon  = d.ID_Kho_muon,
                        Ma_vat_tu = d.Ma_vat_tu,
                        Ten_vat_tu = v.Ten_vat_tu,
                        So_luong = d.So_luong,
                        Ma_phieu_xuat_tam = d.Ma_phieu_xuat_tam,
                        ID_chat_luong = d.Id_chat_luong,
                        Ten_chat_luong = c.Loai_chat_luong,
                       // Ten_kho  = k.Ten_kho,

                        }
                        ).ToList();
              dbcxtransaction.Commit();
              DataTable ds = Utilities.clsThamSoUtilities.ToDataTable(dm);
              return ds;
              }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:32,代码来源:clsKho_Muon_Vat_Tu.cs

示例8: Insert

        public int Insert()
        {
            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            // insert
            using (var dbcxtransaction = help.ent.Database.BeginTransaction())
            {
                try
                {
                    var t = new Vat_Tu_Goi_Dau_Ky //Make sure you have a table called test in DB
                    {
                        ID_VT_Goi_Dau = this.ID_VT_Goi_Dau,
                        Ma_vat_tu = this.Ma_vat_tu,                   // ID = Guid.NewGuid(),
                        So_Luong = this.So_Luong,
                        ID_ky = this.ID_ky,
                        ID_chat_luong = this.ID_chat_luong,
                        ID_kho = this.ID_kho,
                    };

                    help.ent.Vat_Tu_Goi_Dau_Ky.Add(t);
                    help.ent.SaveChanges();
                    dbcxtransaction.Commit();
                    return 1;
                }
                catch (Exception ex)
                {
                    dbcxtransaction.Rollback();
                    return 0;

                }
            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:32,代码来源:clsVatTuGoiDauKy.cs

示例9: CheckTonTaiSoDK

 public bool CheckTonTaiSoDK()
 {
     DatabaseHelper help = new DatabaseHelper();
     help.ConnectDatabase();
     bool has = help.ent.Vat_Tu_Goi_Dau_Ky.Any(cus => cus.Ma_vat_tu == Ma_vat_tu && cus.ID_chat_luong ==ID_chat_luong && cus.ID_kho == ID_kho);
     return has;
 }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:7,代码来源:clsVatTuGoiDauKy.cs

示例10: CheckTonTaiSoDK

 public bool CheckTonTaiSoDK(string maphieu ,string mavattu, int cl)
 {
     DatabaseHelper help = new DatabaseHelper();
       help.ConnectDatabase();
       bool has = help.ent.No_vat_tu.Any(cus => cus.Ma_phieu_xuat_tam == maphieu &&cus.Ma_vat_tu == mavattu && cus.Id_chat_luong == cl);
       return has;
 }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:7,代码来源:clsNoVatTu.cs

示例11: Insert

        public int Insert(DatabaseHelper help)
        {
            {
               try
               {
                   var t = new Can_tru_no_nhap_ngoai //Make sure you have a table called test in DB
                   {
                       Id_chat_luong = this.Id_chat_luong,
                       Ma_vat_tu = this.Ma_vat_tu,                   // ID = Guid.NewGuid(),
                       So_luong_can_tru = this.So_luong_can_tru,
                       Ma_phieu_nhap = this.Ma_phieu_nhap,
                       Ma_phieu_nhap_no = this.Ma_phieu_nhap_no,
                   };

                   help.ent.Can_tru_no_nhap_ngoai.Add(t);
                   help.ent.SaveChanges();
                   //dbcxtransaction.Commit();
                   return 1;
               }
               catch (Exception ex)
               {
                   //dbcxtransaction.Rollback();
                   return 0;

               }
               }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:27,代码来源:clsCanTruNoNhapNgoai.cs

示例12: CheckTonTaiSoDK

 public bool CheckTonTaiSoDK()
 {
     DatabaseHelper help = new DatabaseHelper();
     help.ConnectDatabase();
     bool has = help.ent.Dm_Kho_Muon_Ngoai.Any(cus => cus.Ten_kho_muon == Ten_kho);
     return has;
 }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:7,代码来源:clsDMKhoNgoai.cs

示例13: RandomMaPhieu

        public static string RandomMaPhieu()
        {
            DateTime today = DateTime.Today;
            string year = today.ToString("yy");
            string month = today.ToString("MM");
            string day = today.ToString("dd");
            //kiểm tra xem ngày hiện tại có mã số nào chưa ?\
            //nếu có thì dd.mm.yy.xx+1 vào
            //nếu chưa có thì tạo dd.mm.yy.00

            DatabaseHelper help = new DatabaseHelper();
            help.ConnectDatabase();
            var showPiece = (help.ent.Chi_Tiet_Phieu_Xuat_Tam
               .FirstOrDefault(p => p.Ma_phieu_xuat_tam == help.ent.Chi_Tiet_Phieu_Xuat_Tam.Max(x => x.Ma_phieu_xuat_tam)));
            if (showPiece != null && showPiece.Ma_phieu_xuat_tam.Contains(day + "." + month + "." + year))
            {
                string[] temp = showPiece.Ma_phieu_xuat_tam.Split('.');
                int value = int.Parse(temp[temp.Length]) + 1;
                return day + month + year + showPiece;
            }
            else
            {
                //   showPiece.Ma_phieu_xuat_tam.Split
                return (string)(day + "." + month + "." + year + "." + "0000");
            }
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:26,代码来源:clsPhieuXuatTamVatTu.cs

示例14: AlterarFuncionario

        /// <summary>
        ///     Trata da alteração do destino
        /// </summary>
        private void AlterarFuncionario()
        {
            // Valida se o campo destino está vazio
            if (string.IsNullOrEmpty(tbFuncionario.Text)) {
                // Informa ao usuário que é necessário preencher o campo destino
                MessageBox.Show("Você não preencheu o campo nome");
            }

            //
            else {
                // Cria objeto de acesso ao banco de dados
                var objAltDestino = new DatabaseHelper();

                // Criamos o dicionario de dados com as chaves e valores
                var dctDados = new Dictionary<string, string>();

                // Incluimos no dicionario o campo de destino
                dctDados.Add("c_funcionario", tbFuncionario.Text);

                // Valida se consegue inserir informação no banco de dados
                if (objAltDestino.Update("dados.funcionario", dctDados, "id =" + CodID)) {
                    // Mostra mensagem de sucesso
                    MessageBox.Show("Funcionário alterado com sucesso");
                }
                else {
                    // Mostra mensagem de erro
                    MessageBox.Show("Ocorreu erro ao tentar alterar o funcionário\nContate o seu administrador");
                }

                // Fecha a janela
                Close();
            }
        }
开发者ID:eduvm,项目名称:controlefuncionario,代码行数:36,代码来源:CadFuncionario.xaml.cs

示例15: Delete

        /// <summary>
        /// [Bug] Xóa Item có Liên Kết khóa ngoại với bảng Vật Tư
        /// </summary>
        /// <returns>bool</returns>
        public int Delete(DM_Don_vi_tinh dvt)
        {
            DatabaseHelper help = new DatabaseHelper();
               help.ConnectDatabase();
               help.ent.DM_Don_vi_tinh.Attach(dvt);
               help.ent.DM_Don_vi_tinh.Remove(dvt);
               return help.ent.SaveChanges();

               //Mở
               //m_dbConnection.Open();

               ////Chuẩn bị
               //string sql = "";
               //sql += "Delete from DM_Don_vi_tinh ";
               //sql += "WHERE [email protected]_Don_vi_tinh";

               //SqlCommand command = new SqlCommand(sql, m_dbConnection);

               //command.Parameters.Add("@ID_Don_vi_tinh", SqlDbType.Int).Value = ID_Don_vi_tinh;

               //command.CommandType = CommandType.Text;

               ////Run
               //int result = command.ExecuteNonQuery();

               ////Đóng
               //m_dbConnection.Close();

               //return result;
        }
开发者ID:itcthienkhiem,项目名称:DienLucHocMonCT,代码行数:34,代码来源:clsDM_DonViTinh.cs


注:本文中的DatabaseHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。