Exemple #1
0
        private void wVJ_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            Text = wVJ.Url.ToString();
            if (wVJ.ReadyState == WebBrowserReadyState.Complete && !wVJ.IsBusy)
            {
                HtmlElement        head     = wVJ.Document.GetElementsByTagName("head")[0];
                HtmlElement        scriptEl = wVJ.Document.CreateElement("script");
                IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;
                if (wVJ.Url.AbsolutePath.Contains("/Login.aspx")) // Trang login
                {
                    wVJ.Document.GetElementById("txtUsernameVNiSC").SetAttribute("value", "admin");
                    wVJ.Document.GetElementById("txtMatKhau").SetAttribute("value", "11223399");
                    wVJ.Document.GetElementById("txtAgentCode").SetAttribute("value", "THD");
                    SoLanDangNhap++;
                    if (SoLanDangNhap < 4)
                    {
                        dynamic body         = wVJ.Document.Body.DomElement;
                        dynamic controlRange = body.createControlRange();
                        dynamic element1     = wVJ.Document.GetElementById("imgImageValidate").DomElement;
                        controlRange.add(element1);
                        controlRange.execCommand("Copy", false, null);

                        string res = string.Empty;
RetunA:
                        try
                        {
                            res = XuLyGiaoDien.ConvertImgToText((Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap));
                            if (res.Length < 3)
                            {
                                goto RetunA;
                            }
                        }
                        catch { wVJ.Navigate("http://ags.thanhhoang.vn/Login.aspx"); }

                        if (wVJ.Document.GetElementById("RequiredFieldValidator3").OuterHtml.Contains("VISIBILITY: hidden"))
                        {
                            wVJ.Document.GetElementById("txtImageValidate").SetAttribute("value", res);
                            wVJ.Visible = true;
                            wVJ.Document.GetElementById("btnLogin").InvokeMember("click");
                        }
                        else
                        {
                            goto RetunA;
                        }
                    }
                }
                else if (wVJ.Url.AbsolutePath.Contains("/Default.aspx") || wVJ.Url.AbsolutePath.Contains("/Booking.aspx"))
                {
                    wVJ.Navigate("http://ags.thanhhoang.vn/Accounting.aspx?Do=Deposit");
                }
                else if (wVJ.Url.ToString().EndsWith("Accounting.aspx?Do=Deposit&Act=Add"))
                {
                    HtmlElementCollection hc = wVJ.Document.GetElementsByTagName("option");
                    for (int i = 4; i < hc.Count; i++)
                    {
                        lstdic.Add(hc[i].InnerText);
                    }

                    int o = lstdic.FindIndex(x => x.StartsWith(dl.MaAGS));
                    if (o < 0)
                    {
                        XtraMessageBox.Show("Đại lý chưa được thêm trên ags", "Thông báo");
                        Dispose();
                        Close();
                    }
                    else
                    {
                        element.text = @"function doPost() { document.getElementById('ctl08_ddlSubAgent').options.item(" + o + ").selected = true; }";
                        head.AppendChild(scriptEl);
                        wVJ.Document.InvokeScript("doPost");

                        wVJ.Document.GetElementById("ctl08_txtAmount").SetAttribute("value", spinEdit1.Value.ToString());
                        if (!wVJ.Document.Body.InnerHtml.Contains("Số chứng từ đã tồn tại"))
                        {
                            _SoCT += 1;
                        }
                        else
                        {
                            _SoCT += 2;
                        }
                        wVJ.Document.GetElementById("ctl08_txtDocNo").SetAttribute("value", _SoCT.ToString());
                        wVJ.Document.GetElementById("ctl08_txtDocDate").SetAttribute("value", DateTime.Now.ToString("dd/MM/yyyy"));
                        wVJ.Document.Window.ScrollTo(0, 170);
                    }
                }
                else if (wVJ.Url.AbsolutePath.Contains("/Accounting.aspx"))
                {
                    if (!DaSave)
                    {
                        wVJ.Document.GetElementById("ctl08_btnAddNew").InvokeMember("click");
                    }
                    else
                    {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("SoCT", _SoCT);
                        new D_DAILY().CapNhat(dic, dl.ID);
                        XuLyGiaoDien.Alert("Nhập quỹ AGS thành công", Form_Alert.enmType.Success);
                        Close();
                    }
                    DaSave = !DaSave;
                }
            }
        }
        private void wVJ_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (wVJ.ReadyState == WebBrowserReadyState.Complete && !wVJ.IsBusy)
            {
                HtmlElement        head     = wVJ.Document.GetElementsByTagName("head")[0];
                HtmlElement        scriptEl = wVJ.Document.CreateElement("script");
                IHTMLScriptElement element  = (IHTMLScriptElement)scriptEl.DomElement;
                if (wVJ.Url.ToString().Contains("/Login.aspx")) // Đăng nhập
                {
                    wVJ.Document.GetElementById("txtUsernameVNiSC").SetAttribute("value", "admin");
                    wVJ.Document.GetElementById("txtMatKhau").SetAttribute("value", "11223399");
                    wVJ.Document.GetElementById("txtAgentCode").SetAttribute("value", "THD");
                    SoLanDangNhap++;
                    if (SoLanDangNhap < 4)
                    {
                        dynamic body         = wVJ.Document.Body.DomElement;
                        dynamic controlRange = body.createControlRange();
                        dynamic element1     = wVJ.Document.GetElementById("imgImageValidate").DomElement;
                        controlRange.add(element1);
                        controlRange.execCommand("Copy", false, null);

                        string res = string.Empty;
RetunA:
                        try
                        {
                            res = XuLyGiaoDien.ConvertImgToText((Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap));
                            if (res.Length < 3)
                            {
                                goto RetunA;
                            }
                        }
                        catch { wVJ.Navigate("http://ags.thanhhoang.vn/Login.aspx"); }

                        if (wVJ.Document.GetElementById("RequiredFieldValidator3").OuterHtml.Contains("VISIBILITY: hidden"))
                        {
                            wVJ.Document.GetElementById("txtImageValidate").SetAttribute("value", res);
                            wVJ.Visible = true;
                            wVJ.Document.GetElementById("btnLogin").InvokeMember("click");
                        }
                        else
                        {
                            goto RetunA;
                        }
                    }
                }  // Đăng nhập
                else if (wVJ.Url.ToString().Contains("/Default.aspx") || wVJ.Url.AbsolutePath.Contains("/Booking.aspx")) //Vào trang thêm đại lý
                {
                    wVJ.Navigate("http://ags.thanhhoang.vn/Agent.aspx?Do=SubAgent");
                }
                else if (wVJ.Url.ToString().EndsWith("Agent.aspx?Do=SubAgent&Act=Add"))// Thêm đại lý
                {
                    dldl = _lstDL.Where(w => w.MaAGS.Equals(lstDLAGS[0])).First();
                    wVJ.Document.GetElementById("ctl08_txtAgentCode").SetAttribute("value", lstDLAGS[0]);
                    wVJ.Document.GetElementById("ctl08_txtAgentName").SetAttribute("value", dldl.Ten);
                    if (lstDLAGS.Count > 0)
                    {
                        if (_lstSIChinh.Where(w => w.DaiLy.Equals(dldl.ID) && w.HangBay.Equals(3) && w.Chinh).Count() > 0)
                        {
                            lstQAGS.Remove(lstDLAGS[0]);
                        }
                        lstDLAGS.Remove(lstDLAGS[0]);
                    }
                    wVJ.Document.GetElementById("ctl08_btOK").InvokeMember("click");
                }// Thêm đại lý
                else if (wVJ.Url.ToString().EndsWith("Agent.aspx?Do=SubAgent"))//Kiểm tra tồn tại đại lý
                {
                    if (lstDLAGS.Count == 0)
                    {
                        if (lstQAGS.Count == 0)
                        {
                            wVJ.Navigate("http://ags.thanhhoang.vn/Agent.aspx?Do=Ticketing");
                        }
                        else
                        {
                            wVJ.Navigate("http://ags.thanhhoang.vn/Accounting.aspx?Do=Deposit");
                        }
                    }
                    else
                    {
                        if (!ThemDaiLy)
                        {
                            HtmlElementCollection hc = wVJ.Document.GetElementsByTagName("div");
                            for (int i = 0; i < hc.Count; i++)
                            {
                                if (hc[i].GetAttribute("classname") == "item first")
                                {
                                    if (lstDLAGS.Equals(hc[i].InnerText))
                                    {
                                        lstDLAGS.Remove(hc[i].InnerText);
                                    }
                                }
                            }
                        }

                        ThemDaiLy = lstDLAGS.Count > 0;
                        if (lstDLAGS.Count > 0)
                        {
                            wVJ.Navigate("http://ags.thanhhoang.vn/Agent.aspx?Do=SubAgent&Act=Add");
                        }
                        else
                        {
                            wVJ.Navigate("http://ags.thanhhoang.vn/Agent.aspx?Do=Ticketing");
                        }
                    }
                }//Kiểm tra tồn tại đại lý
                else if (wVJ.Url.ToString().EndsWith("Accounting.aspx?Do=Deposit&Act=Add"))// Thêm quỹ
                {
                    HtmlElementCollection hc = wVJ.Document.GetElementsByTagName("option");
                    for (int i = 4; i < hc.Count; i++)
                    {
                        lstdic.Add(hc[i].InnerText);
                    }

                    int o = lstdic.FindIndex(x => x.StartsWith("0"));
                    if (o < 0)
                    {
                        XtraMessageBox.Show("Đại lý chưa được thêm trên ags", "Thông báo");
                        Dispose();
                        Close();
                    }
                    else
                    {
                        element.text = @"function doPost() { document.getElementById('ctl08_ddlSubAgent').options.item(" + o + ").selected = true; }";
                        head.AppendChild(scriptEl);
                        wVJ.Document.InvokeScript("doPost");

                        wVJ.Document.GetElementById("ctl08_txtAmount").SetAttribute("value", "20000000");
                        wVJ.Document.GetElementById("ctl08_txtDocNo").SetAttribute("value", "1");
                        wVJ.Document.GetElementById("ctl08_txtDocDate").SetAttribute("value", DateTime.Now.ToString("dd/MM/yyyy"));
                        wVJ.Document.Window.ScrollTo(0, 170);
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("SoCT", 2);
                        new D_DAILY().CapNhat(dic, _lstDL.Where(w => w.MaAGS.Equals(lstDLAGS[0])).First().ID);
                    }
                }// Thêm quỹ
                else if (wVJ.Url.ToString().Contains("Accounting.aspx?Do=Deposit"))
                {
                    if (lstQAGS.Count > 0)
                    {
                        wVJ.Document.GetElementById("ctl08_btnAddNew").InvokeMember("click");
                    }
                }// Thêm quỹ
                else if (wVJ.Url.ToString().EndsWith("Agent.aspx?Do=Ticketing&Act=Add"))
                {
                    dldl      = _lstDL.Where(w => w.ID.Equals(_lstSIChinh[iVN].DaiLy)).First();
                    lstMaAGSW = lstMaAGSW.OrderByDescending(w => w).ToList();
                    HtmlElementCollection hc = wVJ.Document.GetElementsByTagName("option");
                    for (int i = 4; i < hc.Count; i++)
                    {
                        lstdic.Add(hc[i].InnerText);
                    }

                    int    o  = lstdic.FindIndex(x => x.StartsWith(dldl.MaAGS));
                    string _a = "AG" + dldl.MaAGS + "1";

                    if (lstMaAGSW.Where(w => w.Contains(dldl.MaAGS)).Count() > 0)
                    {
                        string a = lstMaAGSW.Where(w => w.Contains(dldl.MaAGS)).First();
                        _a = a.Substring(0, a.Length - 1) + (int.Parse(a.Substring(a.Length - 1, 1)) + 1);
                    }

                    wVJ.Document.GetElementById("ctl08_txtTenDangNhap").SetAttribute("value", _a);
                    wVJ.Document.GetElementById("ctl08_txtMatKhau").SetAttribute("value", _lstSIChinh[iVN].MatKhau);
                    wVJ.Document.GetElementById("ctl08_chkChangePassNextLogin").InvokeMember("click");
                    wVJ.Document.GetElementById("ctl08_txtHoTen").SetAttribute("value", dldl.Ten);

                    element.text = @"function doPost() { document.getElementById('ctl08_ddlSubAgent').options.item(" + o + ").selected = true; }";
                    head.AppendChild(scriptEl);
                    wVJ.Document.InvokeScript("doPost");

                    if (_lstSIChinh[iVN].Chinh)
                    {
                        element.text = @"function doPost() { document.getElementById('ctl08_ddlPermission').options.item(1).selected = true; }";
                        head.AppendChild(scriptEl);
                        wVJ.Document.InvokeScript("doPost");
                    }
                    Invoke(new MethodInvoker(delegate()
                    {
                        _lstSIChinh[iVN].End    = true;
                        _lstSIChinh[iVN].SignIn = _a.ToString();
                        GCSI.DataSource         = null;
                        GCSI.DataSource         = _lstSIChinh;
                        GVSI.ExpandAllGroups();
                    }));
                    iVN++;
                }
                else if (wVJ.Url.ToString().EndsWith("Agent.aspx?Do=Ticketing"))
                {
                    lstMaAGSW.Clear();

                    HtmlElementCollection hc = GetElementByClass("table", "table table-bordered").GetElementsByTagName("tr");
                    for (int i = 1; i < hc.Count; i++)
                    {
                        lstMaAGSW.Add(hc[i].GetElementsByTagName("td")[1].InnerText);
                    }

                    for (; iVN < _lstSIChinh.Count; iVN++)
                    {
                        if (_lstSIChinh[iVN].End || _lstSIChinh[iVN].HangBay != 3)
                        {
                            continue;
                        }
                        else
                        {
                            wVJ.Navigate("http://ags.thanhhoang.vn/Agent.aspx?Do=Ticketing&Act=Add");
                            break;
                        }
                    }
                }
            }
        }