Ejemplo n.º 1
0
        public ActionResult ChangeCauHinhWeb(HttpPostedFileBase cauhinh_logo, string ten_congty, int id, string ten_viet_tat, string ten_viet_tat_nm, string ten_nha_may, int id_nm, string dia_chi_nm)
        {
            string fileName = "default_logo.png";

            try
            {
                if (cauhinh_logo != null)
                {
                    //fileName = System.IO.Path.GetFileName(cauhinh_logo.FileName)+"/"+ id;
                    fileName = "logoFactory_" + id + ".png";
                    string path_avatar = System.IO.Path.Combine(Server.MapPath("~/images/logoFactory"), fileName);
                    // file is uploaded
                    cauhinh_logo.SaveAs(path_avatar);
                }

                CongTy ct = CongTyDAO.getCongTyById(id);
                if (ct == null)
                {
                    return(Json(new { success = false, message = "Không tìm thấy thông tin công ty" }));
                }

                ct.Logo       = fileName;
                ct.TenCongTy  = ten_congty;
                ct.TenVietTat = ten_viet_tat;

                var rs = CongTyDAO.updateCongTyInformation(ct);

                NhaMay nm = NhaMayDAO.GetNhaMayById(id_nm);
                if (nm == null)
                {
                    return(Json(new { success = false, message = "Không tìm thấy thông tin nhà máy" }));
                }

                nm.TenNhaMay  = ten_nha_may;
                nm.TenVietTat = ten_viet_tat_nm;
                nm.DiaChi     = dia_chi_nm;

                var rs_nm = NhaMayDAO.updateNhaMayInformation(nm);

                if (rs != "success")
                {
                    return(Json(new { success = false, message = rs }));
                }

                if (rs_nm != "success")
                {
                    return(Json(new { success = false, message = rs_nm }));
                }

                Session["CongTy"] = ct;
                Session["NhaMay"] = nm;
                return(Json(new { success = true, message = string.Empty }));
            }
            catch
            {
                return(Json(new { success = false, message = "Không thể truy cập cơ sở dữ liệu" }));
            }
        }
Ejemplo n.º 2
0
 public FrmCTy()
 {
     InitializeComponent();
     try
     {
         CongTy ct = CongTyDAO.LayDL();
         txtCT.Text      = ct.ChuTich;
         txtDC.Text      = ct.DiaChi;
         txtHotLine.Text = ct.HotLine;
         txtTen.Text     = ct.TenCty;
     }
     catch { }
 }
        // GET: Account
        public ActionResult Login()
        {
            CongTy ct = CongTyDAO.getCongTyByDefault();

            Session["CongTy"] = ct;
            NhaMay nm = NhaMayDAO.GetNhaMayByDefault();

            Session["NhaMay"] = nm;
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            return(View());
        }
Ejemplo n.º 4
0
        private void BtnLuu_Click(object sender, EventArgs e)
        {
            if (txtTen.Text == null || txtHotLine.Text == null || txtDC.Text == null || txtCT == null)
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin!");
                return;
            }
            CongTyDAO DAO = new CongTyDAO();
            CongTy    ct  = new CongTy(txtTen.Text, txtDC.Text, txtCT.Text, txtHotLine.Text);

            if (DAO.Insert(ct))
            {
                MessageBox.Show("Cập nhật thông tin thành công!");
            }
            else
            {
                MessageBox.Show("Vui lòng nhật lại!");
            }
        }
        // call hàm này để check xem có được phép truy cập
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated || HttpContext.Current.Session["User"] != null)
            {
                if (HttpContext.Current.Session["User"] == null)
                {
                    HttpCookie authCookie = HttpContext.Current.Request.Cookies["login_form_cre"];
                    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                    var     serializeModel = JsonConvert.DeserializeObject <CustomSerializeModel>(authTicket.UserData);
                    Account acc            = AccountDAO.GetAccountByID(serializeModel.UserId);
                    HttpContext.Current.Session["User"] = acc;
                }

                HttpContext.Current.Session["CongTy"] = CongTyDAO.getCongTyByDefault();
                HttpContext.Current.Session["NhaMay"] = NhaMayDAO.GetNhaMayByDefault();
                return(true);
            }
            return(false);
        }