public ActionResult SearchCompByCompName(string txtSearch)
        {
            svEmCompany = new emCompanyService();
            Hashtable data = new Hashtable();

            string sqlSelect = "CompID,UserName,CompName,CompCode,FirstName,LastName,CompDistrictID,CompProvinceID,CompAddrLine1,CompAddrLine2,CompPhone,Email";
            string sqlWhere  = "IsDelete = 0 AND CompName ='" + txtSearch + "'";
            var    emCompany = svEmCompany.SelectData <view_emCompanyMember>(sqlSelect, sqlWhere).First();


            var ContactName = emCompany.FirstName + " " + emCompany.LastName;
            var CompAddr    = emCompany.CompAddrLine1;

            data.Add("UserName", emCompany.UserName);
            data.Add("CompID", emCompany.CompID);
            data.Add("CompCode", emCompany.CompCode);
            data.Add("CompName", emCompany.CompName);
            data.Add("ContactName", ContactName);
            data.Add("CompDistrictID", emCompany.CompDistrictID);
            data.Add("CompProvinceID", emCompany.CompProvinceID);
            data.Add("CompAddr", CompAddr);
            data.Add("CompPhone", emCompany.CompPhone);
            data.Add("CompEmail", emCompany.Email);


            return(Json(data));
        }
        public void UpdateContactEmail(int CompID, string Email)
        {
            if (CompID > 0)
            {
                svCompany   = new CompanyService();
                svEmCompany = new emCompanyService();

                var Company = svCompany.SelectData <b2bCompany>("*", "IsDelete = 0 AND CompID =" + CompID).First();
                Company.ContactEmail = Email;
                Company = svCompany.SaveData <b2bCompany>(Company, "CompID");

                if (svCompany.IsResult)
                {
                    var emCompany = svEmCompany.SelectData <emCompany>("*", "IsDelete = 0 AND CompID = " + Company.emCompID).First();
                    emCompany.CompEmail = Email;
                    emCompany           = svEmCompany.SaveData <emCompany>(emCompany, "CompID");
                }
            }
        }
        public void SendEmailToSuppliers(FormCollection form)
        {
            if (!string.IsNullOrEmpty(form["hidAllSupplierCompID"]))
            {
                #region variable
                bool IsSend = true;
                var  Detail = "";
                var  mailCC = new List <string>();
                svCompany   = new CompanyService();
                svEmCompany = new emCompanyService();

                Hashtable EmailDetail = new Hashtable();

                #endregion

                #region Set Content & Value For Send Email

                string Subject     = res.Email.lblSubjectSuppliers3 + " : " + form["hidProductName"] + " - " + res.Email.lblWeb_B2BThai;
                string b2bthai_url = res.Pageviews.UrlWeb;
                string pathlogo    = b2bthai_url + "/Content/Default/logo/Ouikum/img_Logo120x74.png";
                string buylead_url = form["txtBuyleadUrl"];

                #region Select Suppliers
                //Convert string to int
                var      getCompID = form["hidAllSupplierCompID"];
                string[] strCompID = getCompID.Split(',');
                string   WhereIN   = CreateWhereIN(strCompID, "CompID");
                string   sqlWhere  = WhereIN + " AND IsDelete = 0";
                string   sqlSelect = "CompID,CompName,ContactFirstName,ContactLastName,ContactPhone,ContactEmail,emCompID";
                var      Companies = svCompany.SelectData <view_Company>(sqlSelect, sqlWhere);
                #endregion


                var      getAttachCompID = form["hidAttachEmailCompID"];
                string[] strAttachCompID = getAttachCompID.Split(',');
                var      mailFrom        = res.Config.EmailNoReply;
                var      mailTo          = new List <string>();

                foreach (var it in Companies)
                {
                    #region use emCompID to query Username and Password
                    EmailDetail["Username"] = "";
                    EmailDetail["Password"] = "";
                    for (int i = 0; i < strAttachCompID.Length; i++)
                    {
                        if (DataManager.ConvertToInteger(strAttachCompID[i]) == it.CompID)
                        {
                            EncryptManager encrypt = new EncryptManager();
                            sqlWhere  = "IsDelete = 0 AND CompID = " + it.emCompID;
                            sqlSelect = "MemberID,CompID,UserName,Password";
                            var Member = svEmCompany.SelectData <view_emCompanyMember>(sqlSelect, sqlWhere).First();
                            EmailDetail["Username"] = Member.UserName;
                            EmailDetail["Password"] = encrypt.DecryptData(Member.Password);
                        }
                    }
                    #endregion

                    //string contectname = "";
                    //if (!string.IsNullOrEmpty(it.ContactFirstName))
                    //{
                    //    contectname = it.ContactFirstName + " " + it.ContactLastName;
                    //}
                    //else
                    //{
                    //    contectname = it.CompName;
                    //}

                    string CompWebsite_url = b2bthai_url + "/CompanyWebsite/" + Url.ReplaceUrl(it.CompName) + "/Main/Index/" + it.CompID;

                    EmailDetail["b2bthaiUrl"]       = b2bthai_url;
                    EmailDetail["pathLogo"]         = pathlogo;
                    EmailDetail["buyleadUrl"]       = buylead_url;
                    EmailDetail["websiteUrl"]       = CompWebsite_url;
                    EmailDetail["compName"]         = it.CompName;
                    EmailDetail["ContactFirstName"] = it.ContactFirstName;
                    EmailDetail["ContactLastName"]  = it.ContactLastName;
                    EmailDetail["ContactPhone"]     = it.ContactPhone;
                    EmailDetail["ContactEmail"]     = it.ContactEmail;
                    EmailDetail["keyword"]          = form["hidProductName"];

                    // data for set msg detail
                    ViewBag.Data = EmailDetail;
                    Detail       = PartialViewToString("UC/Email/PurchaseToSupplier");


                    mailTo.Add(it.ContactEmail);

                    // send email
                }
                IsSend = OnSendByAlertEmail(Subject, mailFrom, mailTo, mailCC, Detail);
                #endregion
            }
        }