Пример #1
0
        private void downloadCụmToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DocUtils.InitFTPQLSX();
            string code    = TextUtils.ToString(grvData.GetFocusedRowCellValue(colCode));
            string oldCode = "";

            if (code.Contains("-"))
            {
                oldCode = code.Split('-')[0];
            }
            string moduleCode = code.Substring(0, 10);

            string pathCkFTP   = "Thietke.Ck/" + moduleCode.Substring(0, 6) + "/" + moduleCode + ".Ck/";
            string comFtpPath  = pathCkFTP + "3D." + moduleCode + "/COM." + moduleCode + "/";
            string dmvtFtpPath = pathCkFTP + "VT." + moduleCode + ".xlsm";

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang download cụm"))
                {
                    string ftpPathCum = TextUtils.GetPathOfCum(code);
                    TextUtils.DownloadFtpFolder(ftpPathCum, fbd.SelectedPath);

                    string        parentPath = Path.GetDirectoryName(ftpPathCum);
                    List <string> listPath   = TextUtils.GetListFolderInFtpPath(parentPath);
                    foreach (string path in listPath)
                    {
                        string pathName = Path.GetFileName(path);
                        if (oldCode == "")
                        {
                            if (pathName.StartsWith(code + "-"))
                            {
                                TextUtils.DownloadFtpFolder(path, fbd.SelectedPath);
                            }
                        }
                        else
                        {
                            if (pathName.StartsWith(oldCode))
                            {
                                TextUtils.DownloadFtpFolder(path, fbd.SelectedPath);
                            }
                        }
                    }

                    DocUtils.DownloadFile(fbd.SelectedPath, Path.GetFileName(dmvtFtpPath), dmvtFtpPath);
                    DataTable dtDMVT = TextUtils.ExcelToDatatableNoHeader(fbd.SelectedPath + "/" + Path.GetFileName(dmvtFtpPath), "DMVT");
                    File.Delete(fbd.SelectedPath + "/" + Path.GetFileName(dmvtFtpPath));
                    DataRow[] drs = dtDMVT.Select("F4 = '" + code + "'");
                    if (drs.Length > 0)
                    {
                        string    stt    = TextUtils.ToString(drs[0]["F1"]);
                        DataRow[] drsCum = dtDMVT.Select("F1 like '" + stt + "%' and F4 not like '" + moduleCode + "%'");
                        foreach (DataRow row in drsCum)
                        {
                            string hang      = TextUtils.ToString(row["F10"]);
                            string codeVT    = TextUtils.ToString(row["F4"]);
                            string unit      = TextUtils.ToString(row["F6"]);
                            string localPath = fbd.SelectedPath + "/COM." + moduleCode + "/" + hang;
                            if (unit == "BỘ" && codeVT.StartsWith("TPAD.") && hang == "TPA")
                            {
                                TextUtils.DownloadFtpFolder(comFtpPath + hang + "/" + codeVT, localPath);
                            }
                            else
                            {
                                List <string> listFilePath = new List <string>();
                                listFilePath = TextUtils.GetListFileInFtpPath(comFtpPath + hang);
                                foreach (string item in listFilePath)
                                {
                                    string itemCode = Path.GetFileNameWithoutExtension(item).Replace(" ", "");
                                    if (itemCode.ToLower() == codeVT.ToLower())
                                    {
                                        DocUtils.DownloadFile(localPath, Path.GetFileName(item), item);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }