Beispiel #1
0
        public bool Insert(PhieuChi phieuChi)
        {
            try
            {
                string         query       = "SELECT * FROM PhieuChi";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table = GetData();
                DataRow row = table.NewRow();
                row["NhanVienId"]  = phieuChi.NhanVienId;
                row["NguoiDungId"] = phieuChi.NguoiDungId;
                row["ngayChi"]     = phieuChi.NgayChi;
                row["noiDung"]     = phieuChi.NoiDung;
                row["ghiChu"]      = phieuChi.GhiChu;
                row["soTien"]      = phieuChi.SoTien;

                table.Rows.Add(row);

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public bool Update(PhieuChi phieuChi)
        {
            try
            {
                string         query       = "SELECT * FROM PhieuChi";
                SqlDataAdapter dataAdapter = new SqlDataAdapter(query, connection);
                table            = GetData();
                table.PrimaryKey = new DataColumn[] { table.Columns[0] };
                DataRow row = table.Rows.Find(phieuChi.PhieuChiId);

                if (row != null)
                {
                    row["NhanVienId"]  = phieuChi.NhanVienId;
                    row["NguoiDungId"] = phieuChi.NguoiDungId;
                    row["ngayChi"]     = phieuChi.NgayChi;
                    row["noiDung"]     = phieuChi.NoiDung;
                    row["ghiChu"]      = phieuChi.GhiChu;
                    row["soTien"]      = phieuChi.SoTien;
                }

                SqlCommandBuilder sqlCommandBuilder = new SqlCommandBuilder(dataAdapter);
                dataAdapter.Update(table);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #3
0
        public bool CapNhatPhieuChi(PhieuChi pcobj)
        {
            try
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                string     statement = "EXEC PHIEUCHI_Upd @MaPC, @CodePC, @Ngaytao, @Lydo, @Sotien, @MaNV";
                SqlCommand cmd       = new SqlCommand(statement, conn);
                cmd.Parameters.Add("@MaPC", System.Data.SqlDbType.VarChar).Value    = pcobj.MiMaPC.ToString();
                cmd.Parameters.Add("@CodePC", System.Data.SqlDbType.VarChar).Value  = pcobj.MsCodePC;
                cmd.Parameters.Add("@Ngaytao", System.Data.SqlDbType.VarChar).Value = pcobj.MdtNgaytao.ToString();
                cmd.Parameters.Add("@Lydo", System.Data.SqlDbType.NVarChar).Value   = pcobj.MsLydo;
                cmd.Parameters.Add("@Sotien", System.Data.SqlDbType.VarChar).Value  = pcobj.MiSotien.ToString();
                cmd.Parameters.Add("@MaNV", System.Data.SqlDbType.VarChar).Value    = pcobj.MiMaNV.ToString();
                cmd.ExecuteNonQuery();

                conn.Close();
                return(true);
            }
            catch (Exception)
            {
                conn.Close();
                return(false);
            }
        }
Beispiel #4
0
        public PhieuChi PhieuChiByMaPhieuChi(string sMaPC)
        {
            try
            {
                if (conn.State != System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }

                SqlCommand cmd = new SqlCommand("EXEC PHIEUCHI_ById @MaPC ", conn);
                cmd.Parameters.Add("@MaPC", SqlDbType.VarChar).Value = sMaPC;
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);
                conn.Close();
                PhieuChi result = new PhieuChi(Int32.Parse(dt.Rows[0][0].ToString()),
                                               dt.Rows[0][1].ToString(),
                                               Convert.ToDateTime(dt.Rows[0][2].ToString()),
                                               dt.Rows[0][3].ToString(),
                                               Int32.Parse(dt.Rows[0][4].ToString()),
                                               Int32.Parse(dt.Rows[0][5].ToString()),
                                               Int32.Parse(dt.Rows[0][6].ToString()));
                return(result);
            }
            catch (Exception)
            {
                conn.Close();
                return(null);
            }
        }
Beispiel #5
0
 public void DeletePC(String id)
 {
     using (CellphoneComponentEntities db = new CellphoneComponentEntities())
     {
         PhieuChi nv = (from item in db.PhieuChis
                        where item.MaPhieuChi == id
                        select item).SingleOrDefault();
         db.PhieuChis.Remove(nv);
         db.SaveChanges();
     }
 }
Beispiel #6
0
        public void InsertPC(DTO_PhieuChi obj)
        {
            using (CellphoneComponentEntities db = new CellphoneComponentEntities())
            {
                var result = db.Database
                             .SqlQuery <String>("select MaNhanVien from dbo.NhanVien where TenNhanVien = N'" + obj.TenNhanVien + "'")
                             .FirstOrDefault();
                PhieuChi phieuChi = new PhieuChi();
                phieuChi.MaPhieuChi   = obj.MaPhieuChi;
                phieuChi.NgayChi      = obj.NgayChi;
                phieuChi.NgayChinhSua = obj.NgayChinhSua;
                phieuChi.MaPhieuNhap  = obj.MaPhieuNhap;
                phieuChi.GhiChu       = obj.GhiChu;
                phieuChi.TongTienChi  = obj.TongTienChi;
                phieuChi.MaNhanVien   = result;

                db.PhieuChis.Add(phieuChi);
                db.SaveChanges();
            }
        }