Beispiel #1
0
        //Them nha cung cap
        public int InsertSupplierMySQL(string pName, string pPhone, string pEmail, string pAddress, string pTaxcode, string pIdgroup)
        {
            if (IsSupplierMySQL(pName) != 0)
            {
                return(1);
            }
            else
            {
                try
                {
                    DbSpaDataContext db = new DbSpaDataContext();

                    Supplier sup = new Supplier();
                    sup.ID      = GetIDMaxSupplierMySQL() + 1;
                    sup.NAME    = pName;
                    sup.PHONE   = pPhone;
                    sup.EMAIL   = pEmail;
                    sup.ADDRESS = pAddress;
                    sup.TAXCODE = Convert.ToInt32(pTaxcode);
                    sup.IDGROUP = Convert.ToInt32(pIdgroup);

                    db.Suppliers.InsertOnSubmit(sup);
                    db.SubmitChanges();
                    return(2);
                }
                catch
                {
                    return(3);
                }
            }
        }
Beispiel #2
0
 //Cập nhật lại quyền
 public bool UpdateRole(string pIdGroupUs, string pIdScreen, string pRole)
 {
     try
     {
         dc = new DbSpaDataContext();
         GrandRight gr = dc.GrandRights.Where(t => t.IDGROUPUSER == Convert.ToInt32(pIdGroupUs) && t.IDSCREEN == pIdScreen).FirstOrDefault();
         gr.ROLE = Convert.ToInt32(pRole);
         dc.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #3
0
 //Xóa người dùng khỏi nhóm
 public bool DeleteUserOutGroup(string pUserName, string pIdGroup)
 {
     try
     {
         dc = new DbSpaDataContext();
         UserGroupUser user = dc.UserGroupUsers.Where(t => t.USERNAME == pUserName && t.IDGROUPUSER == Convert.ToInt32(pIdGroup)).FirstOrDefault();
         dc.UserGroupUsers.DeleteOnSubmit(user);
         dc.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #4
0
 //Xoa nha cung cap
 public bool DeleteSupplierMySQL(string pID)
 {
     try
     {
         DbSpaDataContext db  = new DbSpaDataContext();
         Supplier         sup = db.Suppliers.Where(t => t.ID == Convert.ToInt32(pID)).FirstOrDefault();
         db.Suppliers.DeleteOnSubmit(sup);
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #5
0
        //MYSQL - Thêm khách hàng đồng thời tạo tài khoản khách hàng User: Số đt KH, Pass : 1 (Mặc định)
        public int InsertCustomerMySQL(string pName, string pSex, string pPhone, string pAddress, int pTypeCus, string pBirtday)
        {
            //Username: Số đt khách hàng, Password: CMND khách hàng
            if (IsAccountMySQL(pPhone) != 0)
            {
                return(1);//Tồn tại tài khoản
            }
            else
            {
                try
                {
                    DbSpaDataContext db  = new DbSpaDataContext();
                    ProfileCu        cus = new ProfileCu();
                    cus.IDPROFILE = GetIDMaxProFileMySQL() + 1;
                    cus.IDTYPE    = pTypeCus;
                    cus.NAME      = pName;
                    cus.BIRTHDAY  = Convert.ToDateTime(pBirtday);
                    cus.PHONE     = pPhone;
                    cus.SEX       = Convert.ToString(pSex);
                    cus.ADDRESS   = Convert.ToString(pAddress);
                    cus.STATUS    = 1;

                    db.ProfileCus.InsertOnSubmit(cus);
                    db.SubmitChanges();
                    //("INSERT INTO profile_cus(ID_PROFILE,ID_TYPE,NAME,SEX,ADDRESS,PHONE,BIRTHDAY,`STATUS`)VALUES('" + (GetIDMaxProFileMySQL() + 1 )+ "','"+pTypeCus+"',N'"+pName+"',N'"+pSex+"',N'"+pAddress+"','"+pPhone+"','"+pBirtday+"',1)", Properties.Settings.Default.DbSpaDataContextConnectionString);
                    //MySqlConnection conn = new MySqlConnection();
                    //string sql = "INSERT INTO profile_cus(ID_PROFILE,ID_TYPE,NAME,SEX,ADDRESS,PHONE,BIRTHDAY,`STATUS`)VALUES('" + (GetIDMaxProFileMySQL() + 1) + "','" + pTypeCus + "',N'" + pName + "',N'" + pSex + "',N'" + pAddress + "','" + pPhone + "','" + pBirtday + "',1)";
                    //conn.ConnectionString = Properties.Settings.Default.DbSpaDataContextConnectionString;
                    //if(conn.State == ConnectionState.Closed)
                    //{
                    //    conn.Open();
                    //    MySqlCommand cmd = new MySqlCommand(sql, conn);
                    //    cmd.ExecuteNonQuery();
                    //    conn.Close();
                    //}
                    int idprofile = db.ProfileCus.Count();
                    int idUser    = InsertAccountMySQL(idprofile, pPhone, "1"); //thêm thành công sẽ trả về ID_USER vừa thêm
                    return(2);                                                  //Thêm thành công
                }
                catch
                {
                    return(3);//Thêm thất bại
                }
            }
        }
Beispiel #6
0
 //Thêm quyen
 public bool InsertRole(string pIdGroupUs, string pIdScreen, string pRole)
 {
     try
     {
         dc = new DbSpaDataContext();
         GrandRight gr = new GrandRight();
         gr.IDGROUPUSER = Convert.ToInt32(pIdGroupUs);
         gr.IDSCREEN    = pIdScreen;
         gr.ROLE        = Convert.ToInt32(pRole);
         dc.GrandRights.InsertOnSubmit(gr);
         dc.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #7
0
        //Thêm tài khoản MYSQL
        public int InsertUserMySQL(string pUserName, string pPass)
        {
            if (IsUserMySQL(pUserName) == 0)
            {
                DbSpaDataContext acc = new DbSpaDataContext();

                DbSpaContext.User t = new User();
                t.USERNAME = pUserName;
                t.PASSWORD = mh.EncodePass(pPass);
                t.STATUS   = 1;
                acc.Users.InsertOnSubmit(t);
                acc.SubmitChanges();
                return(1);//Cho thêm tài khoản, trả về ID_USER mới vừa thêm
            }
            else
            {
                return(0);//Khách hàng đã tạo tài khoản
            }
        }
Beispiel #8
0
 //Xóa khách hàng MYSQL (Account)
 public int DeleteAccountMySQL(string pPhone)
 {
     if (IsAccountMySQL(pPhone) == 1)
     {
         DbSpaDataContext account = new DbSpaDataContext();
         var query = from acc in account.Accounts
                     where acc.USERNAME.ToString().Equals(pPhone) == true
                     select acc;
         foreach (Account item in query)
         {
             item.STATUS = 0;
         }
         account.SubmitChanges();
         return(1);//Tài khoản bị khóa đồng nghĩa việc xóa tài khoản
     }
     else
     {
         return(0);//Không tồn tại tài khoản
     }
 }
Beispiel #9
0
        //Thêm nhóm khách hàng MYSQL
        public bool InsertGroupCustomerMySQL(string pNameGroup)
        {
            if (IsGroupCustomerMySQL(pNameGroup))
            {
                DbSpaDataContext typeCus = new DbSpaDataContext();

                TypeCu t = new TypeCu();
                t.ID     = MaxIDTypeMySQL() + 1;
                t.NAME   = pNameGroup;
                t.STATUS = 1;

                typeCus.TypeCus.InsertOnSubmit(t);
                typeCus.SubmitChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #10
0
        //Thêm nhóm khách hàng MYSQL
        public bool InsertGroupSupplierMySQL(string pNameGroup)
        {
            if (IsGroupSupplierMySQL(pNameGroup))
            {
                DbSpaDataContext db = new DbSpaDataContext();

                GroupSupplier t = new GroupSupplier();
                t.ID        = MaxIDTypeMySQL() + 1;
                t.NAMEGROUP = pNameGroup;
                t.STATUS    = 1;

                db.GroupSuppliers.InsertOnSubmit(t);
                db.SubmitChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #11
0
 //MySQL Xóa tài khoản,Tại đây thực chất cho khóa tài khoản đồng nghĩa với việc dữ liệu tk vẫn còn
 public int DeleteUserMySQL(string pUserName)
 {
     if (IsUserMySQL(pUserName) == 1)
     {
         // DC_CustomerDataContext account = new DC_CustomerDataContext();
         DbSpaDataContext account = new DbSpaDataContext();
         var query = from acc in account.Users
                     where acc.USERNAME.ToString().Equals(pUserName) == true
                     select acc;
         foreach (User item in query)
         {
             item.STATUS = 0;
         }
         account.SubmitChanges();
         return(1);//Tài khoản bị khóa đồng nghĩa việc xóa tài khoản
     }
     else
     {
         return(0);//Không tồn tại tài khoản
     }
 }
Beispiel #12
0
        //Cap nhat nha cung cap
        public bool UpdateSupplierMySQL(string pID, string pName, string pPhone, string pEmail, string pAddress, string pTaxcode, string pIdgroup)
        {
            try
            {
                DbSpaDataContext db = new DbSpaDataContext();

                Supplier sup = db.Suppliers.Where(t => t.ID == Convert.ToInt32(pID)).FirstOrDefault();
                sup.NAME    = pName;
                sup.PHONE   = pPhone;
                sup.EMAIL   = pEmail;
                sup.ADDRESS = pAddress;
                sup.TAXCODE = Convert.ToInt32(pTaxcode);
                sup.IDGROUP = Convert.ToInt32(pIdgroup);
                db.SubmitChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #13
0
 //Luu anh khach hang
 public bool SaveImgCus(string pID, System.Windows.Forms.PictureBox pImg)
 {
     try
     {
         MemoryStream stream = new MemoryStream();
         pImg.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
         DbSpaDataContext db = new DbSpaDataContext();
         var q = from c in db.ProfileCus
                 where c.IDPROFILE == Convert.ToInt32(pID)
                 select c;
         foreach (ProfileCu item in q)
         {
             item.IMAGE = stream.ToArray();
         }
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #14
0
        //Đổi mật khẩu MySQL
        public bool ChangePassMySQL(string pUserName, string pPassNew, string pPassOld)
        {
            try
            {
                DbSpaDataContext dc = new DbSpaDataContext();
                User             us = dc.Users.Where(t => t.USERNAME == pUserName).FirstOrDefault();

                if (us.PASSWORD == mh.EncodePass(pPassOld))
                {
                    us.PASSWORD = mh.EncodePass(pPassNew);
                }
                else
                {
                    return(false);
                }
                dc.SubmitChanges();
                return(true);//Cap nhat thanh cong
            }
            catch
            {
                return(false);
            }
        }
Beispiel #15
0
        //Lấy tên khách hàng
        public string GetNameCus(string pIdCus)
        {
            DbSpaDataContext db = new DbSpaDataContext();

            return(db.ProfileCus.Where(t => t.IDPROFILE == int.Parse(pIdCus)).FirstOrDefault().NAME.ToString());
        }