Esempio n. 1
0
        string RanDomTen()
        {
            string[] Ho  = new string[] { "NGUYEN", "TRAN", "LE", "PHAM", "HUYNH", "HOANG", "PHAN", "VU", "VO", "DANG", "BUI", "DO", "HO", "NGO", "DUONG", "LY" };
            string[] Ten = new string[] { "Anh", "Bá", "Bách", "Bàng", "Bảo", "Bích", "Bổn", "Chi", "Cương", "Cường", "Dũng", "Duy", "Gia", "Giang", "Hà", "Hải", "Hòa", "Hoài", "Hoàng" };

            return(Ho[new Random().Next(Ho.Count())] + " " + XuLyDuLieu.NotVietKey(Ten[new Random().Next(Ten.Count())].ToUpper()) + " VIET");
        }
        void NguoiThanKhach(bool IsIn = true)
        {
            if (IsIn)
            {
                if (!String.IsNullOrEmpty(_HoHang))
                {
                    string[] rows = _HoHang.Replace("\r\n", ",").Split(',');
                    foreach (string row in rows)
                    {
                        if (!String.IsNullOrEmpty(row))
                        {
                            string[] columns = row.Replace("\t", "|").Split('|');
                            DataRow  dataRow = dt.NewRow();
                            dataRow["col1"] = columns[0];
                            dataRow["col2"] = columns[1];
                            dataRow["col3"] = columns[2];
                            dt.Rows.Add(dataRow);
                        }
                    }
                }
                GCNT.DataSource = dt;
            }
            else
            {
                _HoHang = "";

                Regex digitsOnly = new Regex(@"[^\w\d\s]");
                foreach (DataRow row in dt.Rows)
                {
                    _HoHang += row[0] + "\t" + digitsOnly.Replace(XuLyDuLieu.NotVietKey(row[1].ToString()), "") + "\t" + row[2] + "\r\n";
                }
            }
        }
Esempio n. 3
0
        private void btnGuiMail_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Bạn muốn gửi mail ?", "Câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                D_GIAODICH gdb = new D_GIAODICH();

                List <string> vs = new List <string>();
                if ((txtFileDinhKem.EditValue ?? string.Empty) != string.Empty)
                {
                    vs = txtFileDinhKem.EditValue.ToString().Split(',').ToList();
                }

                int n = lstDaiLy.CheckedItems.Count;
                if (n == 0)
                {
                    XuLyGiaoDien.Alert("Chưa chọn đại lý cần gửi", Form_Alert.enmType.Info);
                }
                else
                {
                    try
                    {
                        O_CAUHINHSMTP cauHinhSMTPO = cauHinhSMTPD.DuLieu();
                        O_MAUEMAIL    ma           = new D_MAUEMAIL().DuLieu()[0];

                        SmtpClient client = new SmtpClient();
                        client.Port                  = cauHinhSMTPO.Port;
                        client.Host                  = cauHinhSMTPO.Host;
                        client.EnableSsl             = cauHinhSMTPO.SSL;
                        client.Timeout               = 10000;
                        client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                        client.UseDefaultCredentials = false;
                        client.Credentials           = new System.Net.NetworkCredential(cauHinhSMTPO.Email, cauHinhSMTPO.Password);

                        grvCTCongNo.Columns["Hang"].Width       = 50;
                        grvCTCongNo.Columns["SoVeVN"].Width     = 90;
                        grvCTCongNo.Columns["LuyKe"].Width      = 90;
                        grvCTCongNo.Columns["GiaThu"].Width     = 90;
                        grvCTCongNo.Columns["GiaHeThong"].Width = 90;
                        grvCTCongNo.Columns["TaiKhoanCo"].Width = 90;
                        grvCTCongNo.Columns["TenKhach"].Width   = 250;
                        grvCTCongNo.OptionsPrint.AutoWidth      = false;
                        grvCTCongNo.OptionsView.ColumnAutoWidth = false;

                        XlsxExportOptionsEx opt = new XlsxExportOptionsEx();
                        opt.CustomizeCell += op_CustomizeCell;
                        opt.SheetName      = "Bản Công Nợ";


                        bool sendOK = false;
                        if (!XuLyGiaoDien.wait.IsSplashFormVisible)
                        {
                            XuLyGiaoDien.wait.ShowWaitForm();
                        }
                        for (int i = 0; i < n; i++)
                        {
                            O_DAILY dl = lstDaiLy.GetItem(lstDaiLy.CheckedIndices[0]) as O_DAILY;
                            if (!dl.GuiMail)
                            {
                                int index1 = lstDaiLy.FindItem(0, true, delegate(ListBoxFindItemArgs ei) { ei.IsFound = object.Equals(dl.ID, ei.ItemValue); });
                                lstDaiLy.SetItemChecked(index1, false);
                                continue;
                            }
                            lstInt.Add(dl.ID);
                            string            daily     = string.Format("{0}", dl.ID);
                            List <O_GIAODICH> lstCongNo = gdb.LayDanhSachCN((DateTime)dtpTuNgay.EditValue, (DateTime)dtpDenNgay.EditValue, daily, true);
                            txtMauEmail.HtmlText = ma.NoiDung.Replace("{0}", dl.MaDL).Replace("{1}", XuLyDuLieu.NotVietKey(dl.Ten));

                            if ((dl.EmailKeToan ?? string.Empty) == string.Empty)
                            {
                                goto RE1;
                            }

                            string[] EmailKeToanString = Regex.Replace(dl.EmailKeToan, @"\t|\n|\r", "|").Replace("||", "|").Split('|');
                            for (int ii = 0; ii < EmailKeToanString.Count(); ii++)
                            {
                                if (EmailKeToanString[ii].Length > 5)
                                {
                                    MailMessage mm = new MailMessage();
                                    mm.From         = new MailAddress("*****@*****.**", "Thành Hoàng");
                                    mm.BodyEncoding = UTF8Encoding.UTF8;
                                    mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                                    mm.IsBodyHtml = true;
                                    RichEditMailMessageExporter exporter = new RichEditMailMessageExporter(txtMauEmail, mm);
                                    exporter.Export();
                                    mm.To.Add(new MailAddress(EmailKeToanString[ii]));
                                    //mm.To.Add(new MailAddress("*****@*****.**"));
                                    if (lstCongNo.Count > 1)
                                    {
                                        XuLyGiaoDien.wait.SetWaitFormDescription("Gửi cho: " + dl.Ten + " (" + (i + 1) + "/" + n + ").");
                                        CTGiaoDichDindingSource.DataSource = lstCongNo;
                                        mm.Subject = "Công Nợ - " + dl.Ten + " - Từ ngày " + ((DateTime)dtpTuNgay.EditValue).ToString("dd_MM_yyyy") + " - đến ngày " + ((DateTime)dtpDenNgay.EditValue).ToString("dd_MM_yyyy");

                                        #region Xuất excel
                                        gridCTCongNo.ForceInitialize();
                                        string strFile = @"C:\CongNo\" + dl.Ten + " - " + ((DateTime)dtpTuNgay.EditValue).ToString("dd_MM_yyyy") + " - " + ((DateTime)dtpDenNgay.EditValue).ToString("dd_MM_yyyy") + ".xlsx";
                                        Directory.CreateDirectory(@"C:\CongNo");
                                        gridCTCongNo.ExportToXlsx(strFile, opt);
                                        #endregion

                                        mm.Attachments.Add(new Attachment(strFile));
                                        foreach (string g in vs)
                                        {
                                            if (g.Count() > 0)
                                            {
                                                mm.Attachments.Add(new Attachment(g));
                                            }
                                        }
                                        client.Send(mm);

                                        sendOK = true;
                                        mm.Attachments.Dispose();
                                        if (File.Exists(strFile))
                                        {
                                            File.Delete(strFile);
                                        }
                                    }
                                }
                            }
                            RE1 :
                            int index = lstDaiLy.FindItem(0, true, delegate(ListBoxFindItemArgs ei) { ei.IsFound = object.Equals(dl.ID, ei.ItemValue); });
                            lstDaiLy.SetItemChecked(index, false);
                        }

                        if (sendOK)
                        {
                            XuLyGiaoDien.Alert("Gửi mail thành công", Form_Alert.enmType.Success);
                        }
                        else
                        {
                            XuLyGiaoDien.Alert("Gửi mail không thành công", Form_Alert.enmType.Warning);
                        }
                    }
                    catch (Exception ex) { XtraMessageBox.Show(ex.Message, "Thông báo"); }
                    gdb.ChayCapNhatLuyKe(lstInt);
                    if (XuLyGiaoDien.wait.IsSplashFormVisible)
                    {
                        XuLyGiaoDien.wait.CloseWaitForm();
                    }
                }
            }
        }
Esempio n. 4
0
        private void btnGuiMail_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show("Bạn muốn gửi mail ?", "Câu hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                int n = lstDaiLyz.CheckedItems.Count;
                if (n == 0)
                {
                    XuLyGiaoDien.Alert("Chưa chọn đại lý tìm", Form_Alert.enmType.Info);
                }
                else
                {
                    O_CAUHINHSMTP cauHinhSMTPO = cauHinhSMTPD.DuLieu();
                    O_MAUEMAIL    ma           = new D_MAUEMAIL().DuLieu()[0];

                    SmtpClient client = new SmtpClient();
                    client.Port                  = cauHinhSMTPO.Port;
                    client.Host                  = cauHinhSMTPO.Host;
                    client.EnableSsl             = cauHinhSMTPO.SSL;
                    client.Timeout               = 10000;
                    client.DeliveryMethod        = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials           = new System.Net.NetworkCredential(cauHinhSMTPO.Email, cauHinhSMTPO.Password);


                    GCG.Visible = true; if (!XuLyGiaoDien.wait.IsSplashFormVisible)
                    {
                        XuLyGiaoDien.wait.ShowWaitForm();
                    }
                    List <long> a     = new List <long>();
                    string      daily = string.Format("{0}", lstDaiLyz.CheckedItems[0]);
                    a.Add(long.Parse(lstDaiLyz.CheckedItems[0].ToString()));
                    for (int i = 1; i < n; i++)
                    {
                        a.Add(long.Parse(lstDaiLyz.CheckedItems[i].ToString()));
                        daily += string.Format(",{0}", lstDaiLyz.CheckedItems[i]);
                    }

                    lst = new D_HOADON().DuLieu(string.Format("CONVERT(date, NgayThucHien) BETWEEN '{0}' AND '{1}' AND MaHD <> '0' AND ((GiaYeuCau - GiaHeThong) * PhanTram / 100) > 0 AND IDKhachHang in ({2}) ORDER BY IDKhachHang,MaHD,MaCho,GiaHeThong Desc", bdtpTu.DateTime.ToString("yyyyMMdd"), bdtpDen.DateTime.ToString("yyyyMMdd"), daily));

                    DevExpress.XtraPrinting.XlsxExportOptionsEx opt = new DevExpress.XtraPrinting.XlsxExportOptionsEx();
                    opt.CustomizeCell += op_CustomizeCell;
                    opt.SheetName      = "Bản CTHD";
                    opt.ApplyFormattingToEntireColumn = DefaultBoolean.False;
                    opt.ShowGridLines = false;

                    bool sendOK = false;
                    foreach (int b in a)
                    {
                        O_DAILY dl = lstDaiLy.Where(w => w.ID.Equals(b)).ToList()[0];
                        txtMauEmail.HtmlText = ma.NoiDung.Replace("{0}", dl.MaDL).Replace("{1}", XuLyDuLieu.NotVietKey(dl.Ten));
                        string[] EmailKeToanString = System.Text.RegularExpressions.Regex.Replace(dl.EmailKeToan, @"\t|\n|\r", "|").Replace("||", "|").Split('|');
                        for (int ii = 0; ii < EmailKeToanString.Count(); ii++)
                        {
                            if (EmailKeToanString[ii].Length > 5)
                            {
                                List <O_HOADON> lstTam1 = lst.Where(w => w.IDKhachHang.Equals(b)).OrderBy(w => w.MaHD.Replace(" ", string.Empty)).ToList();
                                List <O_HOADON> lstTam  = new List <O_HOADON>();
                                string          newrow  = string.Empty;
                                foreach (O_HOADON hd in lstTam1)
                                {
                                    if (newrow != hd.MaHD && newrow.Length > 0)
                                    {
                                        lstTam.Add(new O_HOADON());
                                    }
                                    lstTam.Add(hd);
                                    newrow = hd.MaHD;
                                }

                                lstTam.Add(new O_HOADON()
                                {
                                    ID         = -1,
                                    GiaHeThong = lstTam.Sum(w => w.GiaHeThong),
                                    GiaYeuCau  = lstTam.Sum(w => w.GiaYeuCau),
                                    CL1        = lstTam.Sum(w => w.CL1),
                                    CL2        = lstTam.Sum(w => w.CL2),
                                });

                                MailMessage mm = new MailMessage();
                                mm.From         = new MailAddress("*****@*****.**", "Thành Hoàng");
                                mm.BodyEncoding = UTF8Encoding.UTF8;
                                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                                mm.IsBodyHtml = true;
                                RichEditMailMessageExporter exporter = new RichEditMailMessageExporter(txtMauEmail, mm);
                                exporter.Export();
                                mm.To.Add(new MailAddress(EmailKeToanString[ii]));
                                //mm.To.Add(new MailAddress("*****@*****.**"));

                                XuLyGiaoDien.wait.SetWaitFormDescription("Excel cho: " + dl.Ten);
                                guiOBindingSource.DataSource = lstTam;
                                string strFile = @"C:\HoaDon\CT HoaDon " + dl.Ten + ".xlsx";
                                System.IO.Directory.CreateDirectory(@"C:\HoaDon");
                                GVG.ExportToXlsx(strFile, opt);

                                mm.Attachments.Add(new Attachment(strFile));
                                mm.Subject = "Bảng kê hóa đơn Tháng " + bdtpTu.DateTime.Month + " - " + dl.Ten;
                                client.Send(mm);
                                sendOK = true;
                                mm.Attachments.Dispose();
                                if (File.Exists(strFile))
                                {
                                    File.Delete(strFile);
                                }
                            }
                        }
                    }
                    GCG.Visible = false;
                    if (XuLyGiaoDien.wait.IsSplashFormVisible)
                    {
                        XuLyGiaoDien.wait.CloseWaitForm();
                    }
                    if (sendOK)
                    {
                        XuLyGiaoDien.Alert("Gửi mail thành công", Form_Alert.enmType.Success);
                    }
                    else
                    {
                        XuLyGiaoDien.Alert("Gửi mail không thành công", Form_Alert.enmType.Warning);
                    }
                }
            }
        }
Esempio n. 5
0
        void Wb()
        {
            var chromeDriverService = ChromeDriverService.CreateDefaultService();
            var options             = new ChromeOptions();
            //chromeDriverService.HideCommandPromptWindow = true;
            O_NHACUNGCAP cCO = new D_NHACUNGCAP().DuLieu().Where(w => w.Ten.Equals("VJ")).First();

            try { driver = new ChromeDriver(chromeDriverService, options, TimeSpan.FromSeconds(300)); }
            catch { options.BinaryLocation = @"C:\Program Files\Google\Chrome\Application\chrome.exe"; driver = new ChromeDriver(chromeDriverService, options, TimeSpan.FromSeconds(300)); }

            js   = driver as IJavaScriptExecutor;
            wait = new WebDriverWait(driver, TimeSpan.FromMinutes(5));

            for (int i = 0; i < _lstSIChinh.Count; i++)
            {
                if (_lstSIChinh[i].End || _lstSIChinh[i].HangBay != 2)
                {
                    continue;
                }

                #region VJ
                if (!driver.Url.Contains("vietjetair"))
                {
                    driver.Navigate().GoToUrl("https://www.vietjetair.com/Sites/Web/vi-VN/Home");
                    wait.Until(d => d.PageSource.Contains("https://agents.vietjetair.com/sitelogin.aspx?lang=vi"));
                    js.ExecuteScript("location.href = 'https://agents.vietjetair.com/sitelogin.aspx?lang=vi';");
                    wait.Until(d => d.PageSource.Contains("javascript:SubmitForm();"));
                    driver.FindElement(By.CssSelector("input[name='txtAgentID']")).SendKeys(cCO.TaiKhoan); //thẻ có tên là
                    driver.FindElement(By.CssSelector("#txtAgentPswd")).SendKeys(cCO.MatKhau);             // # ID
                    driver.FindElement(By.CssSelector(".button")).Click();                                 // . Class
                    wait.Until(d => d.PageSource.Contains("button_big subAgencgyBtn"));
                    driver.FindElement(By.LinkText("Đại lý con")).Click();
                    wait.Until(d => CountElementByClassName(driver, "a", "user-icon ng-scope") == 5);
                    ChromeFindElementByClassName("a", "user-icon ng-scope", 0).Click();
                    wait.Until(d => d.FindElements(By.LinkText("New user")).Count > 0);
                    wait.Until(d => d.PageSource.Contains("base-loading-class") == false);
                }

                O_DAILY dl = _lstDL.Where(w => w.ID.Equals(_lstSIChinh[i].DaiLy)).ToList()[0];

                switch (_lstSIChinh[i].CanLam)
                {
                case 0:
                    driver.FindElement(By.LinkText("New user")).Click();
                    wait.Until(d => d.PageSource.Contains("btn btn-secondary ng-binding"));
                    Thread.Sleep(1000);
                    wait.Until(d => d.PageSource.Contains("form-control ng-pristine ng-untouched ng-valid-we-validate ng-valid-maxlength ng-valid ng-valid-required"));

                    Thread.Sleep(2000);
                    object a = ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-valid-we-validate ng-valid-maxlength ng-valid ng-valid-required", 0).GetAttribute("value");
                    Invoke(new MethodInvoker(delegate()
                    {
                        _lstSIChinh[i].SignIn = a.ToString();
                        GCSI.DataSource       = null;
                        GCSI.DataSource       = _lstSIChinh;
                        GVSI.ExpandAllGroups();
                    }));

                    Actions build = new Actions(driver);
                    Thread.Sleep(1000);
                    build.Click(ChromeFindElementByClassName("div", "ui-select-container ui-select-multiple ui-select-bootstrap dropdown form-control ng-valid ng-valid-ui-select-required", 0)).Build().Perform();

                    Thread.Sleep(1000);
                    wait.Until(d => d.FindElements(By.LinkText("TA")).Count > 0);
                    driver.FindElement(By.LinkText("TA HOLD")).Click();

                    if (_lstSIChinh[i].Chinh)
                    {
                        wait.Until(d => d.PageSource.Contains("base-loading-class") == false);
                        js.ExecuteScript("document.getElementsByClassName('ui-select-search input-xs ng-pristine ng-valid ng-touched')[0].click()");
                        try
                        {
                            driver.FindElement(By.LinkText("TA")).Click();
                        }
                        catch { }
                    }

                    ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-invalid ng-invalid-required", 0).SendKeys(_lstSIChinh[i].MatKhau);
                    ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-valid-we-validate ng-invalid ng-invalid-required", 0).SendKeys(_lstSIChinh[i].MatKhau);

                    ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-valid-we-validate ng-invalid ng-invalid-required ng-valid-maxlength ng-valid-email", 0).SendKeys((dl.EmailGiaoDich ?? "*****@*****.**").Replace("\r\n", "|").Split('|')[0]);
                    ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-valid-we-validate ng-invalid ng-invalid-required ng-valid-maxlength", 0).SendKeys(dl.DiDong ?? "0919415995");
                    ChromeFindElementByClassName("input", "form-control ng-pristine ng-untouched ng-invalid ng-invalid-required ng-valid-maxlength", 0).SendKeys(_lstSIChinh[i].SignIn + "-" + XuLyDuLieu.NotVietKey(dl.Ten).Replace(" ", string.Empty));

                    new SelectElement(ChromeFindElementByClassName("select", "form-control ng-pristine ng-untouched ng-invalid ng-invalid-required")).SelectByIndex(47);

                    ChromeFindElementByClassName("button", "btn btn-secondary ng-binding", 0).Submit();

                    Thread.Sleep(1000);
                    wait.Until(d => d.PageSource.Contains("base-loading-class") == false);
                    wait.Until(d => d.FindElements(By.LinkText("New user")).Count > 0);
                    _lstSIChinh[i].End = true;

                    break;
                }
                #endregion
            }
            driver.Close();
            driver.Quit();
        }