Exemplo n.º 1
0
        /// <summary>
        /// Insert data
        /// </summary>
        /// <param name="dataInsert"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        ///
        public bool InsertData(Object dataInsert, string tableName)
        {
            _logger.Start("InsertData");
            _logger.Param("TableName", tableName);
            bool result = false;

            try
            {
                sqlMap.BeginTransaction();
                Hashtable param = new Hashtable();

                #region Tao du lieu cho values de import
                ArrayList arrValues  = new ArrayList();
                ArrayList arrColumns = new ArrayList();

                this.SetDataToArrayListForInsert(dataInsert, ref arrColumns, ref arrValues);

                #endregion

                //ten table
                param.Add("tablename", tableName);
                //Cac column trong table
                param.Add("columns", arrColumns);
                //gia tri cua cac du lieu can insert
                param.Add("values", arrValues);
                sqlMap.Insert("Common.InsertRow", param);

                //commit du lieu
                sqlMap.CommitTransaction();
                //them moi du lieu thanh cong
                result = true;
            }
            catch (Exception ex)
            {
                sqlMap.RollbackTransaction();
                _logger.Error(ex);
            }

            _logger.End("InsertData");
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the data rows.
        /// </summary>
        /// <param name="toTable">To table.</param>
        /// <param name="fromTable">From table.</param>
        public static void SetDataRows(DataTable toTable, DataTable fromTable)
        {
            if (toTable == null)
            {
                return;
            }

            toTable.Clear();

            if (fromTable == null)
            {
                return;
            }
            logger.Start("SetDataRows");
            foreach (DataRow dataRow in fromTable.Rows)
            {
                toTable.ImportRow(dataRow);
            }
            logger.End("SetDataRows");
            return;
        }
Exemplo n.º 3
0
        public string send_Mail(string strEncryptCode, string mailto, string Subject, string Contents, AbsentModels model, string hotento)
        {
            _logger.Start("send_Mail");
            try
            {
                string linkname = string.Format(Functiontring.ReturnStringFormatthongtincauhinhmail("linkname"));
                strEncryptCode = linkname.Trim() + strEncryptCode + "&mailcanhan=" + mailto;
                if ((model.machucdanh == "1" && double.Parse(model.songayxinnghi) > 2) || model.machucdanh == "2")
                {
                    strEncryptCode = strEncryptCode + "&hovaten=" + model.hovaten + "&tenphongban=" + model.tenphongban
                                     + "&songayxinnghi=" + model.songayxinnghi + "&ngayxinnghitu=" + model.ngayxinnghitu + "&ngayxinnghiden=" + model.ngayxinnghiden
                                     + "&lydoxinnghi=" + model.lydoxinnghi + "&sodienthoai=" + model.sodienthoai + "&mailcanhan=" + model.email;
                }

                //string smtp_port = string.Format(Functiontring.ReturnStringFormatthongtincauhinhmail("smtp_port"));
                string smtp_host = string.Format(Functiontring.ReturnStringFormatthongtincauhinhmail("smtp_host"));
                string smtp_user = string.Format(Functiontring.ReturnStringFormatthongtincauhinhmail("smtp_user"));



                #region

                StringBuilder sb = new StringBuilder();
                sb.Append("<html><head>");
                sb.Append("<link rel='stylesheet' type='text/css' href='theme.css' />");
                sb.Append("</head>");
                sb.Append("<body style='margin-top: 20px; padding: 0; width: 650px; font-size: 1em;color:black;'>"); //margin: 0 auto;  de canh giua

                sb.Append("<table cellpadding='0' cellspacing='0' width='650px' >");
                sb.Append("<tbody>");
                sb.Append("<tr>");
                sb.Append("<td height='76px' width='650px' >");
                sb.Append("<table cellpadding='0' cellspacing='0' width='100%'>");

                sb.Append("<tbody>");
                sb.Append("<tr>");
                sb.Append("<td>");

                sb.Append("<div style='width:150px;float:left;height :45px; line-height:45px; padding-top:10px;'>");
                sb.Append("<img src='http://i.imgur.com/yKqNNy2.png'  alt='ddd' style='width:100px; height:45px;'/>");
                sb.Append("</div>");
                sb.Append("</td>");

                sb.Append("<td>");
                sb.Append("<div style='width:400px; text-align:center;font-weight: bold;float:left;line-height:45px'>");
                sb.Append("<p style= 'width:400px;text-align:center;font-size:18px;font-weight:bold;line-height:45px;padding-left:80px;float:left;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ĐƠN XIN NGHỈ PHÉP</p>");
                sb.Append("</div>");
                sb.Append("</td>");

                sb.Append("</tr>");
                sb.Append("</tbody>");
                sb.Append("</table>");
                sb.Append("</td>");
                sb.Append("</tr>");
                sb.Append("</tbody>");
                sb.Append("</table>");
                sb.Append("<hr style=border: 1px solid #000; width: 100% />");

                sb.Append("<table style='width:650px; font-size:14px;'>");
                sb.Append("<tr><td style='padding-left:10px;'><p><strong><em><u>Kính gửi Anh/Chị:</u></em>&nbsp;" + hotento + "</strong></p></td></tr>");

                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Họ và tên:             " + model.hovaten + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Công tác tại:          " + model.tenphongban + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Số ngày xin nghỉ:      " + model.songayxinnghi + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Từ ngày:               " + model.ngayxinnghitu + " đến ngày: " + model.ngayxinnghiden + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Lý do xin nghỉ:        " + model.lydoxinnghi + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Số điện thoại:         " + model.sodienthoai + "" + "</td></tr>");
                sb.Append("<tr><td style='float:left;height :22px; line-height:22px; padding-left:10px;'>" + "Email:                 " + model.email + "" + "</td></tr>");  //style='background-color:blue;color:white'
                sb.Append("<tr><td style='float:left; padding-left:10px; padding-top:10px;'><a href='" + strEncryptCode + "&dongy=1'> Đồng ý</a>&nbsp;&nbsp;<a href='" + strEncryptCode + "&dongy=3'>Không đồng ý</a></td></tr>");
                sb.Append("</table>");
                sb.Append("</body>");
                sb.Append("</html>");

                #endregion

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(smtp_user, mailto.Trim());
                message.From         = new MailAddress(mailto.Trim(), Subject, System.Text.Encoding.UTF8);
                message.Subject      = Subject;
                message.Body         = sb.ToString();
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml   = true;
                message.Priority     = MailPriority.High;
                SmtpClient client = new SmtpClient(smtp_host);
                client.UseDefaultCredentials = true;
                try
                {
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception caught in CreateTestMessage2(): {0}",
                                      ex.ToString());
                }
                return("Successfull!");
            }
            catch (Exception ms)
            {
                _logger.Error(ms);
                return(ms.Message);
            }
            _logger.End("send_Mail");
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor without arguments
 /// </summary>
 public SQLMapEmployee()
 {
     //
     // TODO:
     //
     logger.Start("Constructor SQLMapEmployee");
     try
     {
         sqlMapEmployee = (SqlMapper)Mapper.Instance();
     }
     catch (Exception ex)
     {
         logger.Error(ex.ToString());
     }
     logger.End("Constructor SQLMap");
 }
Exemplo n.º 5
0
        public ActionResult Login(TaiKhoanModels model, string returnUrl, string captcha)
        {
            _logger.Start("Login");
            bool bCaptcha = false;

            ViewBag.isNhapCaptcha = false;
            LoginServices service = new LoginServices();

            try
            {
                //neu so lan user dang nhap vuot qua gioi han se bi lock
                if (Session[strSessionLoginFail] == null)
                {
                    Session[strSessionLoginFail] = 0;
                }
                int loginFail = (int)Session[strSessionLoginFail];
                if (!string.IsNullOrEmpty(captcha) && !string.IsNullOrWhiteSpace(captcha))
                {
                    if (captcha == Session[strSessionCaptcha].ToString())
                    {
                        bCaptcha = true;
                    }
                }
                if (loginFail < RICONS.Core.Constants.CST_Common.CST_Lock || bCaptcha)
                {
                    #region kiem tra user login tren he thong AD admin
                    bool   validAD          = false;
                    string matkhaudangnnhap = model.matkhau;
                    string tendangnhap      = model.tendangnhap.Trim().Split('@')[0].ToLower();
                    var    passWordDecrypt  = EncDec.DecryptStringAES(model.matkhau);
                    try
                    {
                        using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "newtecons.vn", tendangnhap, passWordDecrypt))
                        {
                            validAD = context.ValidateCredentials(tendangnhap, passWordDecrypt);
                            UserPrincipal user_ad = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, tendangnhap);
                            if (validAD)
                            {
                                #region
                                var user = service.GetLoginData(new M_TaiKhoan()
                                {
                                    tendangnhap = tendangnhap,
                                    xoa         = CST_Common.CST_NOT_DELETE,
                                    kichhoat    = CST_Common.CST_ACTIVE
                                });
                                TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                                TaiKhoanModels   modeltk     = new TaiKhoanModels();
                                // Lay du lieu employee
                                //var dlemployee = serTaiKhoan.GetDataEmployee(tendangnhap);
                                if (user == null)
                                {
                                    #region
                                    //if (dlemployee != null)
                                    //{
                                    //    modeltk.manhansu = dlemployee.manhansu;
                                    //    modeltk.hoten = dlemployee.hoten;
                                    //    modeltk.machucdanh = dlemployee.machucdanh;
                                    //    modeltk.tenchucdanh = dlemployee.tenchucdanh;
                                    //    modeltk.maphongban = dlemployee.maphongban;

                                    //    if (dlemployee.phongban_congtruong.ToString().ToLower() == "false")
                                    //        modeltk.phongban_congtruong = "0";
                                    //    else modeltk.phongban_congtruong = "1";

                                    //}
                                    modeltk.tendangnhap = tendangnhap;
                                    model.madonvi       = 1;
                                    modeltk.thudientu   = user_ad.EmailAddress;
                                    modeltk.chucdanhkpi = "1";
                                    bool kq = serTaiKhoan.AddUser(modeltk, 0);
                                    user = service.GetLoginData(new M_TaiKhoan()
                                    {
                                        tendangnhap = tendangnhap,
                                        xoa         = CST_Common.CST_NOT_DELETE,
                                        kichhoat    = CST_Common.CST_ACTIVE
                                    });
                                    #endregion
                                }
                                //else if (dlemployee != null)
                                //{
                                //    //Cập nhật manhansu,machucdanh,maphongban
                                //    user.manhansu = dlemployee.manhansu;
                                //    user.maphongban = dlemployee.maphongban;
                                //    user.machucdanh = dlemployee.machucdanh;
                                //    user.tenchucdanh = dlemployee.tenchucdanh;
                                //    user.hoten = dlemployee.hoten;
                                //    user.sodienthoai = dlemployee.sodienthoai;
                                //    user.thudientu = user_ad.EmailAddress;
                                //    user.ngaysinh = dlemployee.ngaysinh;
                                //    user.chucdanhkpi = user.chucdanhkpi;
                                //    if(dlemployee.phongban_congtruong.ToString().ToLower()=="false")
                                //        user.phongban_congtruong = "0";
                                //    else user.phongban_congtruong = "1";

                                //    if (user.chucdanhkpi.Trim() == "" || user.chucdanhkpi == null)
                                //        user.chucdanhkpi = "1";
                                //    bool kqcapnhat = serTaiKhoan.Updatemanhansu(user.mataikhoan, user.manhansu, user.machucdanh.ToString(), user.maphongban, user.hoten, user.chucdanhkpi, user.phongban_congtruong);
                                //}
                                var lstPhongBanDonVis = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                                {
                                    mataikhoan = user.mataikhoan
                                });
                                user.phongBanDonVis = lstPhongBanDonVis;
                                AddSession(user);
                                UpdateLoginState(tendangnhap, false, loginFail);
                                //chuyen trang
                                _logger.End("Login");
                                return(RedirectToAction("Index", "WeedMeeting"));

                                //return RedirectToLocal(returnUrl);
                                #endregion
                            }
                            else if (!validAD)
                            {
                                #region
                                var user = service.GetLoginData(new M_TaiKhoan()
                                {
                                    tendangnhap = model.tendangnhap,
                                    matkhau     = EncDec.EncodePassword(passWordDecrypt),
                                    xoa         = CST_Common.CST_NOT_DELETE,
                                    kichhoat    = CST_Common.CST_ACTIVE
                                });
                                if (user != null)
                                {
                                    TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                                    var lstPhongBanDonVis        = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                                    {
                                        mataikhoan = user.mataikhoan
                                    });
                                    user.phongBanDonVis = lstPhongBanDonVis;
                                    AddSession(user);
                                    UpdateLoginState(model.tendangnhap, false, loginFail);
                                    _logger.End("Login");
                                    return(RedirectToAction("Index", "WeedMeeting"));
                                }
                                else
                                {
                                    try
                                    {
                                        UpdateLoginState(model.tendangnhap, true, loginFail);
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.Error(ex);
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        validAD = false;
                        _logger.Info(ex);
                    }
                    #endregion

                    #region kiem tra user login local

                    if (!validAD)
                    {
                        var user = service.GetLoginData(new M_TaiKhoan()
                        {
                            tendangnhap = model.tendangnhap,
                            matkhau     = EncDec.EncodePassword(passWordDecrypt),
                            xoa         = CST_Common.CST_NOT_DELETE,
                            kichhoat    = CST_Common.CST_ACTIVE
                        });
                        if (user != null)
                        {
                            TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                            var lstPhongBanDonVis        = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                            {
                                mataikhoan = user.mataikhoan
                            });
                            user.phongBanDonVis = lstPhongBanDonVis;
                            AddSession(user);
                            UpdateLoginState(model.tendangnhap, false, loginFail);
                            _logger.End("Login");
                            return(RedirectToAction("Index", "WeedMeeting"));
                        }
                        else
                        {
                            try
                            {
                                UpdateLoginState(model.tendangnhap, true, loginFail);
                            }
                            catch (Exception ex)
                            {
                                _logger.Error(ex);
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    ViewBag.isNhapCaptcha = true;
                    UpdateLoginState(model.tendangnhap, true, loginFail);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _logger.End("CheckLogin");
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }