Пример #1
0
 public DataTable GetDMVT(string filePath)
 {
     try
     {
         DataTable dt1 = TextUtils.ExcelToDatatable(filePath.Trim(), "DMVT");
         DataTable dt  = dt1.Copy();
         for (int i = 0; i <= 4; i++)
         {
             dt.Rows.RemoveAt(0);
         }
         //for (int i = 0; i <4; i++)
         //{
         //    dt.Rows.RemoveAt(dt.Rows.Count - 1);
         //}
         for (int i = 1; i <= 5; i++)
         {
             dt.Columns.RemoveAt(4);
         }
         dt.Columns.RemoveAt(dt.Columns.Count - 1);
         dt.Columns.RemoveAt(dt.Columns.Count - 1);
         return(dt1);
     }
     catch (Exception)
     {
         return(new DataTable());
     }
 }
Пример #2
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            int       count   = 0;
            DataTable dt      = TextUtils.ExcelToDatatable(@"D:\\123.xlsx", "Sheet1");
            DataTable tblLink = TextUtils.Select("exec spGetModuleOfProject");

            foreach (DataRow item in dt.Rows)
            {
                try
                {
                    string           code  = item[0].ToString();
                    ModuleErrorModel error = (ModuleErrorModel)ModuleErrorBO.Instance.FindByAttribute("Code", code)[0];
                    if (error.ProjectCode != "")
                    {
                        continue;
                    }
                    string       projectText = item["F3"].ToString();
                    ModulesModel module      = (ModulesModel)ModulesBO.Instance.FindByPK(error.ModuleID);
                    DataRow[]    dt1         = tblLink.Select("ProjectCode like '%" + projectText + "%' and ProductCode = '" + module.Code + "'");
                    if (dt1.Length > 0)
                    {
                        error.ProjectCode = dt1[0]["ProjectCode"].ToString();
                        ModuleErrorBO.Instance.Update(error);
                        count++;
                    }
                }
                catch (Exception)
                {
                }
            }
            MessageBox.Show(count + " OK");
        }
Пример #3
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                DataTable dt = new DataTable();

                OpenFileDialog ofd = new OpenFileDialog();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    dt = TextUtils.ExcelToDatatable(ofd.FileName);
                }

                if (dt.Rows.Count <= 0)
                {
                    return;
                }
                if (dt.Rows[6][2].ToString() == "")
                {
                    return;                                //check mã dự án
                }
                txtProjectCode.Text      = dt.Rows[6][2].ToString();
                txtProjectName.Text      = dt.Rows[6][5].ToString();
                txtContractCode.Text     = dt.Rows[7][2].ToString();
                txtContractName.Text     = txtContractCode.Text.Trim() != "" ? "Hợp đồng kinh tế số " + dt.Rows[7][2].ToString() : "";
                txtCurator.Text          = dt.Rows[5][5].ToString();
                txtCustomerName.Text     = dt.Rows[9][2].ToString();
                txtLastCustomerName.Text = dt.Rows[9][5].ToString();
                txtReception.Text        = dt.Rows[8][5].ToString();

                txtRequirement.Text = dt.Rows[8][2].ToString();
                txtPriority.Text    = dt.Rows[5][2].ToString();

                cboStatus.SelectedIndex = 0;

                for (int i = 13; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i][3].ToString() == "" || dt.Rows[i][1].ToString() == "")
                    {
                        continue;
                    }
                    ProductsModel model = new ProductsModel();
                    model.PjCode   = dt.Rows[i][3].ToString();
                    model.PjName   = dt.Rows[i][1].ToString();
                    model.Quantity = TextUtils.ToInt(dt.Rows[i][5]);
                    model.Unit     = dt.Rows[i][4].ToString();
                    _listProducts.Add(model);
                }
            }
            catch (Exception ex)
            {
                TextUtils.ShowError(ex);
            }
        }
Пример #4
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            try
            {
                string FileName = Application.StartupPath + "\\Templates\\ImportSP.xlsx";
                Process.Start(FileName);
                if (MessageBox.Show("Bạn đã lưu lại file Excel chưa?\n Sẵn sàng Import vào phần mềm!", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    btnNew_Click(null, null);
                    btnSave.Visible = true;
                    DataTable dt = TextUtils.ExcelToDatatable(FileName, "SanPhamDA");

                    if (dt.Rows.Count <= 0)
                    {
                        return;
                    }

                    dt.Columns[0].ColumnName = "TenTheoHopDong";
                    dt.Columns[1].ColumnName = "MaTheoHopDong";
                    dt.Columns[2].ColumnName = "SL";

                    if (dt.Rows.Count > 0)
                    {
                        IEnumerable <DataRow> dr = (from order in dt.AsEnumerable()
                                                    where order.Field <string>("TenTheoHopDong") != "" && order.Field <string>("TenTheoHopDong") != null
                                                    select order);
                        if (dr.Count() > 0)
                        {
                            dt = dr.CopyToDataTable();
                        }
                        else
                        {
                            dt = new DataTable();
                        }
                        //.CopyToDataTable();
                    }
                    DataTable dtt = m_DataSource;
                    foreach (DataRow item in dt.Rows)
                    {
                        dtt.ImportRow(item);
                    }
                    grdData.DataSource = dtt;
                    grvData.BestFitColumns();
                    grdData.Focus();
                }
            }
            catch (Exception ex)
            {
                TextUtils.ShowError(ex);
            }
        }
Пример #5
0
        private void btnBrowse_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = false;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Lấy dữ liệu trong file excel!"))
                {
                    btnBrowse.Text = ofd.FileName;
                    //dt = TextUtils.ExcelToDatatable(btnBrowse.Text, "Sheet1");
                    dt = TextUtils.ExcelToDatatable(btnBrowse.Text, "THONGKELOI");
                    grdData.DataSource = dt;
                }
            }
        }
Пример #6
0
 DataTable getDmvtNormal()
 {
     try
     {
         string strFileName = @"\\SERVER\data2\Thietke\Luutru\Thietkechuan\Thietke.Ck\" + ProductCode.Substring(0, 6) + "/" +
                              ProductCode + ".Ck" + "/VT." + ProductCode + ".xlsm ";
         if (File.Exists(strFileName))
         {
             return(TextUtils.ExcelToDatatable(strFileName, "DMVT"));
         }
     }
     catch
     {
     }
     return(new DataTable());
 }
Пример #7
0
 public DataTable GetDMVTHang1(string filePath)
 {
     try
     {
         DataTable dt1 = TextUtils.ExcelToDatatable(filePath, "Sheet");
         DataTable dt  = dt1.Copy();
         for (int i = 0; i <= 4; i++)
         {
             dt.Rows.RemoveAt(0);
         }
         return(dt);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Пример #8
0
 DataTable getDmvtFTP()
 {
     try
     {
         DocUtils.InitFTPQLSX();
         string model       = ProductCode;
         string strFilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
         strFilePath = strFilePath.Remove(strFilePath.LastIndexOf(@"\"));
         string strFTPFileName = @"//Thietke.Ck/" + model.Substring(0, 6) + "/" + model + ".Ck" + "/VT." + model + ".xlsm ";
         DocUtils.DownloadFile(strFilePath, model + ".xlsm", strFTPFileName);
         DataTable dt = TextUtils.ExcelToDatatable(strFilePath + "/" + model + ".xlsm", "DMVT");
         File.Delete(strFilePath + "/" + model + ".xlsm");
         return(dt);
     }
     catch
     {
         return(new DataTable());
     }
 }
Пример #9
0
 DataTable getDmvtFTP()
 {
     try
     {
         DocUtils.InitFTPQLSX();
         string model       = _moduleCode;
         string strFilePath = System.IO.Path.GetTempFileName();
         strFilePath = strFilePath.Remove(strFilePath.LastIndexOf(@"\"));
         string strFTPFileName = @"//Thietke.Ck/" + model.Substring(0, 6) + "/" + model + ".Ck" + "/VT." + model + ".xlsm ";
         DocUtils.DownloadFile(strFilePath, "dmvt.xlsm", strFTPFileName);
         DataTable dt = TextUtils.ExcelToDatatable(strFilePath + "/" + "dmvt.xlsm", "DMVT");
         File.Delete(strFilePath + "/" + "dmvt.xlsm");
         return(dt);
     }
     catch
     {
         return(new DataTable());
     }
 }
Пример #10
0
        void loadChildModule(string moduleCode, int parentID)
        {
            DocUtils.InitFTPQLSX();
            string _serverPathCK = string.Format("Thietke.Ck/{0}/{1}.Ck/VT.{1}.xlsm", moduleCode.Substring(0, 6), moduleCode);
            string localPath     = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (DocUtils.CheckExits(_serverPathCK))
            {
                DocUtils.DownloadFile(localPath, "VT." + moduleCode + ".xlsm", _serverPathCK);
            }
            else
            {
                return;
            }
            DataTable dtDMVT = TextUtils.ExcelToDatatable(localPath + "/VT." + moduleCode + ".xlsm", "DMVT");

            if (File.Exists(localPath + "/VT." + moduleCode + ".xlsm"))
            {
                File.Delete(localPath + "/VT." + moduleCode + ".xlsm");
            }
            DataRow[] drs = dtDMVT.Select("F4 like 'TPAD%' and len(F4) = 10");
            if (drs.Length > 0)
            {
                for (int i = 0; i < drs.Length; i++)
                {
                    string  stt = TextUtils.ToString(drs[i]["F1"]);
                    decimal qty = TextUtils.ToDecimal(drs[i]["F7"]);

                    if (stt.Contains("."))
                    {
                        string[]  arr       = stt.Split('.');
                        string    parentSTT = arr[0];
                        DataRow[] drs0      = dtDMVT.Select("F1 ='" + parentSTT + "'");
                        if (drs0.Length > 0)
                        {
                            qty *= TextUtils.ToDecimal(drs0[0]["F7"]);
                        }
                        for (int j = 1; j < arr.Length - 1; j++)
                        {
                            parentSTT += "." + TextUtils.ToString(arr[i]);
                            DataRow[] drsC = dtDMVT.Select("F1 ='" + parentSTT + "'");
                            if (drsC.Length > 0)
                            {
                                qty *= TextUtils.ToDecimal(drsC[0]["F7"]);
                            }
                        }
                    }

                    string code = TextUtils.ToString(drs[i]["F4"]);
                    string name = "";

                    DataTable dt = LibQLSX.Select("select FolderName from SourceCode with(nolock) where FolderCode = '" + code + "'");
                    if (dt.Rows.Count > 0)
                    {
                        name = TextUtils.ToString(dt.Rows[0]["FolderName"]);
                    }
                    else
                    {
                        name = TextUtils.ToString(drs[i]["F2"]);
                    }
                    _count++;
                    DataRow dr = _dtModule.NewRow();
                    dr["F3"]       = name;
                    dr["F5"]       = code;
                    dr["F7"]       = qty;
                    dr["ID"]       = _count;
                    dr["ParentID"] = parentID;

                    _dtModule.Rows.Add(dr);
                    loadChildModule(code, _count);
                }
            }
        }
Пример #11
0
        List <string> getListMail(string ProductCode)
        {
            NVCoKhi = "";
            NVDien  = "";
            NVDT    = "";

            DocUtils.InitFTPQLSX();
            List <string> listMailAddress = new List <string>();

            if (ProductCode.StartsWith("TPAD."))
            {
                string personDien = "";
                try
                {
                    string fdfFileName = string.Format("Thietke.Dn\\{0}\\{1}.Dn\\PRD.{1}\\{1}.Dn.pdf", ProductCode.Substring(0, 6), ProductCode);
                    if (DocUtils.CheckExits(fdfFileName))
                    {
                        DocUtils.DownloadFile("D:/", Path.GetFileName(fdfFileName), fdfFileName);
                        PdfReader reader1 = new PdfReader("D:/" + Path.GetFileName(fdfFileName));
                        personDien = reader1.Info["Author"];
                        reader1.Close();
                        File.Delete("D:/" + Path.GetFileName(fdfFileName));
                    }
                    else
                    {
                        fdfFileName = string.Format("Thietke.Dn/{0}/{1}.Dn/{1}.Dn.pdf", ProductCode.Substring(0, 6), ProductCode);
                        if (DocUtils.CheckExits(fdfFileName))
                        {
                            DocUtils.DownloadFile("D:/", Path.GetFileName(fdfFileName), fdfFileName);
                            PdfReader reader1 = new PdfReader("D:/" + Path.GetFileName(fdfFileName));
                            personDien = reader1.Info["Author"];
                            reader1.Close();
                            File.Delete("D:/" + Path.GetFileName(fdfFileName));
                        }
                    }

                    if (personDien != "")
                    {
                        NVDien     = personDien;
                        personDien = getAddressMail(personDien);
                        if (personDien != "")
                        {
                            listMailAddress.Add(getAddressMail(personDien) + "@tpa.com.vn");
                        }
                    }
                }
                catch
                {
                }

                string _serverPathCK = "Thietke.Ck/" + ProductCode.Substring(0, 6) + "/" + ProductCode + ".Ck/" + "/VT." + ProductCode + ".xlsm";

                try
                {
                    if (DocUtils.CheckExits(_serverPathCK))
                    {
                        if (File.Exists("D:/VT." + ProductCode + ".xlsm"))
                        {
                            File.Delete("D:/VT." + ProductCode + ".xlsm");
                        }
                        //Download file danh mục vật tư
                        DocUtils.DownloadFile("D:/", "VT." + ProductCode + ".xlsm", _serverPathCK);
                        DataTable dtDMVT = TextUtils.ExcelToDatatable("D:/VT." + ProductCode + ".xlsm", "DMVT");
                        File.Delete("D:/VT." + ProductCode + ".xlsm");

                        NVCoKhi = dtDMVT.Rows[2]["F3"].ToString();
                        string ck = getAddressMail(dtDMVT.Rows[2]["F3"].ToString());
                        if (ck != "")
                        {
                            if (!listMailAddress.Contains(ck + "@tpa.com.vn"))
                            {
                                listMailAddress.Add(ck + "@tpa.com.vn");
                            }
                        }

                        try
                        {
                            DataTable dtDT = dtDMVT.Select("F4 like '%PCB%'").CopyToDataTable();
                            if (dtDT.Rows.Count > 0)
                            {
                                string dienTuPath = "Thietke.Dt/PCB/";
                                foreach (DataRow item in dtDT.Rows)
                                {
                                    string code = item["F4"].ToString();
                                    if (code != "")
                                    {
                                        string pathDMVT_DT = dienTuPath + "/" + code + "/PRD." + code + "/VT." + code + ".xls";

                                        if (DocUtils.CheckExits(pathDMVT_DT))
                                        {
                                            try
                                            {
                                                DocUtils.DownloadFile("D:/", Path.GetFileName(pathDMVT_DT), pathDMVT_DT);
                                                DataTable dtDMVT_DT = TextUtils.ExcelToDatatable("D:/VT." + code + ".xls", "DMVT");
                                                File.Delete("D:/VT." + code + ".xls");
                                                NVDT += dtDMVT_DT.Rows[2]["F3"].ToString() + " - " + code + ",";
                                                string dt = getAddressMail(dtDMVT_DT.Rows[2]["F3"].ToString());
                                                if (dt != "")
                                                {
                                                    string personDT = dt + "@tpa.com.vn";
                                                    if (!listMailAddress.Contains(personDT))
                                                    {
                                                        listMailAddress.Add(personDT);
                                                    }
                                                }
                                            }
                                            catch (Exception)
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                catch
                {
                }
            }

            if (ProductCode.StartsWith("PCB."))
            {
                #region Get address of PCB
                string dienTuPath = "Thietke.Dt/PCB/";
                string code       = ProductCode;
                if (code != "")
                {
                    string pathDMVT_DT = dienTuPath + "/" + code + "/PRD." + code + "/VT." + code + ".xls";

                    if (DocUtils.CheckExits(pathDMVT_DT))
                    {
                        try
                        {
                            DocUtils.DownloadFile("D:/", Path.GetFileName(pathDMVT_DT), pathDMVT_DT);
                            DataTable dtDMVT_DT = TextUtils.ExcelToDatatable("D:/VT." + code + ".xls", "DMVT");
                            File.Delete("D:/VT." + code + ".xls");
                            NVDT += dtDMVT_DT.Rows[2]["F3"].ToString() + " - " + code + ",";
                            string dt = getAddressMail(dtDMVT_DT.Rows[2]["F3"].ToString());
                            if (dt != "")
                            {
                                string personDT = dt + "@tpa.com.vn";
                                if (!listMailAddress.Contains(personDT))
                                {
                                    listMailAddress.Add(personDT);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                #endregion
            }

            return(listMailAddress);
        }
Пример #12
0
        private void cboStatus_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (btnBrowse.Text == "")
            {
                return;
            }
            gridControl1.DataSource = null;

            try
            {
                DataTable dt = TextUtils.ExcelToDatatable(btnBrowse.Text, cboStatus.SelectedValue.ToString());

                if (dt.Rows.Count <= 0)
                {
                    return;
                }

                dt.Columns[0].ColumnName = "STT";
                dt.Columns[1].ColumnName = "TenVatTu";
                dt.Columns[2].ColumnName = "MaVatTu";
                dt.Columns[3].ColumnName = "Hang";
                dt.Columns[4].ColumnName = "DonVi";
                dt.Columns[5].ColumnName = "SoLuong";
                dt.Columns[6].ColumnName = "ThongSo";
                dt.Columns[7].ColumnName = "NgayVeDuKien";
                dt.Columns[8].ColumnName = "GhiChu";
                dt.Columns.Add("TenDuAn");
                dt.Columns.Add("MaDuAn");
                string re = dt.Rows[4][2].ToString();
                string te = dt.Rows[4][4].ToString();
                for (int i = 8; i >= 0; i--)
                {
                    dt.Rows.RemoveAt(i);
                }
                //linq lấy các dòng mà code khác rỗng và khác null
                dt = (from order in dt.AsEnumerable()
                      where order.Field <string>("TenVatTu") != "" && order.Field <string>("TenVatTu") != null
                      select order).CopyToDataTable();
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        dt.Rows[i]["TenDuAn"] = re;
                        dt.Rows[i]["MaDuAn"]  = te;
                    }
                }
                gridControl1.DataSource = dt;


                DataTable dt1 = new DataTable();
                foreach (GridColumn colum in gridView1.VisibleColumns)
                {
                    dt1.Columns.Add(colum.FieldName, colum.ColumnType);
                }
                for (int i = 0; i < gridView1.DataRowCount; i++)
                {
                    DataRow row = dt1.NewRow();
                    foreach (GridColumn colum in gridView1.VisibleColumns)
                    {
                        row[colum.FieldName] = gridView1.GetRowCellValue(i, colum);
                    }
                    dt1.Rows.Add(row);
                }
                dt = dt1;
                #region Tinh ngay thuc te
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow row = dt.Rows[i];
                        if (row["NgayYeuCau"].ToString().Trim() != "")
                        {
                            if (row["NgayThucTe"].ToString().Trim() != "")
                            {
                                DateTime ngaymuon = Convert.ToDateTime(row["NgayYeuCau"]);
                                DateTime ngaytra  = Convert.ToDateTime(row["NgayThucTe"]);
                                TimeSpan tim      = ngaytra - ngaymuon;
                                row["ThoiGianDatHangThucTe"] = tim.Days.ToString();
                            }
                        }
                    }
                }
                #endregion
                gridControl1.DataSource = dt;
                gridView1.BestFitColumns();
                gridControl1.Focus();
            }
            catch (Exception ex)
            {
                TextUtils.ShowError(ex);
            }
        }
Пример #13
0
        private void frmSearchModule_Load(object sender, EventArgs e)
        {
            this.Text = ProductCode;

            DocUtils.InitFTPQLSX();
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang load dữ liệu..."))
            {
                try
                {
                    string fdfFileName = string.Format("Thietke.Dn\\{0}\\{1}.Dn\\PRD.{1}\\{1}.Dn.pdf", ProductCode.Substring(0, 6), ProductCode);
                    if (DocUtils.CheckExits(fdfFileName))
                    {
                        DocUtils.DownloadFile("D:/", Path.GetFileName(fdfFileName), fdfFileName);
                        PdfReader reader1 = new PdfReader("D:/" + Path.GetFileName(fdfFileName));
                        txtThietKeDien.Text = reader1.Info["Author"];
                        reader1.Close();
                        File.Delete("D:/" + Path.GetFileName(fdfFileName));
                    }
                    else
                    {
                        fdfFileName = string.Format("Thietke.Dn/{0}/{1}.Dn/{1}.Dn.pdf", ProductCode.Substring(0, 6), ProductCode);
                        if (DocUtils.CheckExits(fdfFileName))
                        {
                            DocUtils.DownloadFile("D:/", Path.GetFileName(fdfFileName), fdfFileName);
                            PdfReader reader1 = new PdfReader("D:/" + Path.GetFileName(fdfFileName));
                            txtThietKeDien.Text = reader1.Info["Author"];
                            reader1.Close();
                            File.Delete("D:/" + Path.GetFileName(fdfFileName));
                        }
                    }
                }
                catch (Exception)
                {
                }

                string _serverPathCK = "Thietke.Ck/" + ProductCode.Substring(0, 6) + "/" + ProductCode + ".Ck/" + "/VT." + ProductCode + ".xlsm";

                try
                {
                    if (DocUtils.CheckExits(_serverPathCK))
                    {
                        if (File.Exists("D:/VT." + ProductCode + ".xlsm"))
                        {
                            File.Delete("D:/VT." + ProductCode + ".xlsm");
                        }
                        //Download file danh mục vật tư
                        DocUtils.DownloadFile("D:/", "VT." + ProductCode + ".xlsm", _serverPathCK);
                        DataTable dtDMVT = TextUtils.ExcelToDatatable("D:/VT." + ProductCode + ".xlsm", "DMVT");

                        File.Delete("D:/VT." + ProductCode + ".xlsm");
                        txtThietKeCoKhi.Text = dtDMVT.Rows[2]["F3"].ToString();

                        try
                        {
                            DataTable dtDT = dtDMVT.Select("F4 like '%PCB%'").CopyToDataTable();
                            if (dtDT.Rows.Count > 0)
                            {
                                string dienTuPath = "Thietke.Dt/PCB/";
                                foreach (DataRow item in dtDT.Rows)
                                {
                                    string code = item["F4"].ToString();
                                    if (code != "")
                                    {
                                        string pathDMVT_DT = dienTuPath + "/" + code + "/PRD." + code + "/VT." + code + ".xls";

                                        if (DocUtils.CheckExits(pathDMVT_DT))
                                        {
                                            try
                                            {
                                                DocUtils.DownloadFile("D:/", Path.GetFileName(pathDMVT_DT), pathDMVT_DT);
                                                DataTable dtDMVT_DT = TextUtils.ExcelToDatatable("D:/VT." + code + ".xls", "DMVT");
                                                File.Delete("D:/VT." + code + ".xls");

                                                txtThietKeDienTu.Text += code + " : " + dtDMVT_DT.Rows[2]["F3"].ToString() + Environment.NewLine;
                                            }
                                            catch (Exception)
                                            {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                catch
                {
                }
            }
        }
Пример #14
0
        void UpdateFTP()
        {
            string    initPath   = @"F:\data\SQL SXLR\DataTPA\Sourcecode\";
            string    cokhiPath  = initPath + "/Thietke.Ck/";
            string    dienTuPath = initPath + "/Thietke.Dt/PCB/";
            string    dienPath   = initPath + "/Thietke.Dn/";
            ArrayList array      = ModulesBO.Instance.FindByExpression(new Expression("Status", 2).And(new Expression("Code", "TPAD", "like")));

            foreach (var row in array)
            {
                ModulesModel module   = (ModulesModel)row;
                string       pathDMVT = cokhiPath + "//" + module.Code.Substring(0, 6) + "//" + module.Code + ".Ck//VT." + module.Code + ".xlsm";
                if (!File.Exists(pathDMVT))
                {
                    continue;
                }
                FileInfo fi = new FileInfo(pathDMVT);

                DataTable dtDMVT         = TextUtils.ExcelToDatatable(pathDMVT, "DMVT");
                DataTable dtListMaterial = GetDMVT(dtDMVT);

                DataTable dtLink = TextUtils.Select("MaterialModuleLink", new Expression("ModuleID", module.ID));

                string filePathIam          = cokhiPath + module.Code.Substring(0, 6) + "/" + module.Code + ".Ck/3D." + module.Code + "/" + module.Code + ".iam";
                string folderPahModuleImage = "";//Hỏi anh Hậu????????????????????????????????

                #region UPDATE TÀI LIỆU THIẾT KẾ CHO SẢN PHẨM
                try
                {
                    int DT = 0;
                    int D  = 0;

                    //string dienPath = "D:\\Thietke.Dn\\" + module.Code.Substring(0, 6) + "\\" + module.Code + ".Dn";
                    if (Directory.Exists(dienPath))
                    {
                        D = 1;
                    }

                    try
                    {
                        if (dtListMaterial.Select("F4 like '%PCB%'").Count() > 0)
                        {
                            DT = 1;
                        }
                    }
                    catch (Exception)
                    {
                    }

                    module.FileElectric   = D;
                    module.FileElectronic = DT;
                    module.FileMechanics  = 1;
                    ModulesBO.Instance.Update(module);
                }
                catch (Exception)
                {
                }
                #endregion UPDATE TÀI LIỆU THIẾT KẾ CHO SẢN PHẨM

                if (dtLink.Rows.Count > 0)
                {
                    int size = TextUtils.ToInt(dtLink.Rows[0]["Size"]);
                    if (size != (int)(fi.Length))
                    {
                        #region Tạo ảnh của sản phẩm
                        try
                        {
                            //IPTDetail.LoadData(filePathIam);
                            //Bitmap bit = new Bitmap(IPTDetail.Image, IPTDetail.Image.Width / 3, IPTDetail.Image.Height / 3);
                            //bit.Save(folderPahModuleImage + "/" + module.Code+".png", ImageFormat.Png);

                            //module.ImagePath = "\\SERVER\\data2\\Thietke\\PHANMEM\\ModuleImage\\" + module.Code + ".png";
                            //ModulesBO.Instance.Update(module);
                        }
                        catch
                        {
                        }
                        #endregion

                        #region THÊM NGƯỜI THIẾT KẾ
                        try
                        {
                            ModuleDesignerBO.Instance.DeleteByAttribute("ModuleID", module.ID);
                            if (dtDMVT.Rows[2]["F3"].ToString() != "")
                            {
                                ModuleDesignerModel model = new ModuleDesignerModel();
                                model.LoginName  = dtDMVT.Rows[2]["F3"].ToString();
                                model.ModuleID   = module.ID;
                                model.WorkDetail = "Thiết kế cơ khí: " + fi.LastWriteTime.ToString("dd/MM/yyyy");
                                model.GroupType  = 0;
                                model.Author     = dtDMVT.Rows[2]["F3"].ToString();
                                ModuleDesignerBO.Instance.Insert(model);
                            }

                            try
                            {
                                if (dtListMaterial.Select("F4 like '%PCB%'").Count() > 0)
                                {
                                    foreach (DataRow item in dtListMaterial.Select("F4 like '%PCB%'"))
                                    {
                                        string code = item["F4"].ToString();
                                        if (code != "")
                                        {
                                            string    pathDMVT_DT = dienTuPath + "/" + code + "/PRD." + code + "/VT." + code + ".xls";
                                            DataTable dtDMVT_DT   = TextUtils.ExcelToDatatable(pathDMVT_DT, "DMVT");

                                            ModuleDesignerModel modelDT = new ModuleDesignerModel();
                                            modelDT.LoginName  = dtDMVT_DT.Rows[2]["F3"].ToString();
                                            modelDT.ModuleID   = module.ID;
                                            modelDT.WorkDetail = "Thiết kế điện tử: " + code;
                                            modelDT.GroupType  = 2;
                                            modelDT.Author     = dtDMVT_DT.Rows[2]["F3"].ToString();
                                            ModuleDesignerBO.Instance.Insert(modelDT);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }
                        catch (Exception)
                        {
                        }
                        #endregion THÊM NGƯỜI THIẾT KẾ

                        #region TẠO DANH MỤC VẬT TƯ CHO MODULE
                        //xóa danh sách vật tư cũ
                        MaterialModuleLinkBO.Instance.DeleteByAttribute("ModuleID", module.ID);
                        try
                        {
                            foreach (DataRow item in dtListMaterial.Rows)
                            {
                                MaterialModuleLinkModel linkModel = new MaterialModuleLinkModel();

                                linkModel.ModuleID = module.ID;

                                //linkModel.DateCreated = fi.LastWriteTime.ToString("dd/MM/yyyy");
                                linkModel.Designer = dtDMVT.Rows[2]["F3"].ToString();
                                linkModel.SizeTK   = (int)(fi.Length);
                                linkModel.Author   = dtDMVT.Rows[2]["F3"].ToString();

                                linkModel.STT       = item["F1"].ToString();
                                linkModel.Name      = item["F2"].ToString();
                                linkModel.ThongSo   = item["F3"].ToString();
                                linkModel.Code      = item["F4"].ToString();
                                linkModel.MaVatLieu = item["F5"].ToString();
                                linkModel.Unit      = item["F6"].ToString();
                                linkModel.Qty       = TextUtils.ToInt(item["F7"].ToString());
                                linkModel.VatLieu   = item["F8"].ToString();
                                linkModel.Weight    = TextUtils.ToDecimal(item["F9"].ToString());
                                linkModel.Hang      = item["F10"].ToString();
                                try
                                {
                                    ArrayList     listMaterial = MaterialBO.Instance.FindByAttribute("Code", linkModel.Code);
                                    MaterialModel model        = (MaterialModel)listMaterial[0];
                                    linkModel.Price    = model.Price;
                                    linkModel.Delivery = model.DeliveryPeriod;
                                }
                                catch (Exception)
                                {
                                    linkModel.Price    = 0;
                                    linkModel.Delivery = 0;
                                }

                                MaterialModuleLinkBO.Instance.Insert(linkModel);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        #endregion TẠO DANH MỤC VẬT TƯ CHO MODULE
                    }
                }
                else
                {
                    #region Tạo ảnh của sản phẩm
                    try
                    {
                        //IPTDetail.LoadData(filePathIam);
                        //Bitmap bit = new Bitmap(IPTDetail.Image, IPTDetail.Image.Width / 3, IPTDetail.Image.Height / 3);
                        //bit.Save(folderPahModuleImage + "/" + module.Code + ".png", ImageFormat.Png);

                        //module.ImagePath = "\\SERVER\\data2\\Thietke\\PHANMEM\\ModuleImage\\" + module.Code + ".png";
                        //ModulesBO.Instance.Update(module);
                    }
                    catch
                    {
                    }
                    #endregion

                    #region THÊM NGƯỜI THIẾT KẾ
                    try
                    {
                        ModuleDesignerModel model = new ModuleDesignerModel();
                        model.LoginName  = dtDMVT.Rows[2]["F3"].ToString();
                        model.ModuleID   = module.ID;
                        model.WorkDetail = "Thiết kế cơ khí: " + fi.LastWriteTime.ToString("dd/MM/yyyy");
                        model.GroupType  = 0;
                        model.Author     = dtDMVT.Rows[2]["F3"].ToString();
                        ModuleDesignerBO.Instance.Insert(model);

                        try
                        {
                            if (dtListMaterial.Select("F4 like '%PCB%'").Count() > 0)
                            {
                                foreach (DataRow item in dtListMaterial.Select("F4 like '%PCB%'"))
                                {
                                    string code = item["F4"].ToString();
                                    if (code != "")
                                    {
                                        string    pathDMVT_DT = dienTuPath + "/" + code + "/PRD." + code + "/VT." + code + ".xls";
                                        DataTable dtDMVT_DT   = TextUtils.ExcelToDatatable(pathDMVT_DT, "DMVT");

                                        ModuleDesignerModel modelDT = new ModuleDesignerModel();
                                        modelDT.LoginName  = dtDMVT_DT.Rows[2]["F3"].ToString();
                                        modelDT.ModuleID   = module.ID;
                                        modelDT.WorkDetail = "Thiết kế điện tử: " + code;
                                        modelDT.GroupType  = 2;
                                        modelDT.Author     = dtDMVT_DT.Rows[2]["F3"].ToString();
                                        ModuleDesignerBO.Instance.Insert(modelDT);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    catch (Exception)
                    {
                    }
                    #endregion THÊM NGƯỜI THIẾT KẾ

                    #region TẠO DANH MỤC VẬT TƯ CHO MODULE
                    try
                    {
                        foreach (DataRow item in dtListMaterial.Rows)
                        {
                            MaterialModuleLinkModel linkModel = new MaterialModuleLinkModel();

                            linkModel.ModuleID = module.ID;

                            //linkModel.DateCreated = fi.LastWriteTime.ToString("dd/MM/yyyy");
                            linkModel.Designer = dtDMVT.Rows[2]["F3"].ToString();
                            linkModel.SizeTK   = (int)(fi.Length);
                            linkModel.Author   = dtDMVT.Rows[2]["F3"].ToString();

                            linkModel.STT       = item["F1"].ToString();
                            linkModel.Name      = item["F2"].ToString();
                            linkModel.ThongSo   = item["F3"].ToString();
                            linkModel.Code      = item["F4"].ToString();
                            linkModel.MaVatLieu = item["F5"].ToString();
                            linkModel.Unit      = item["F6"].ToString();
                            linkModel.Qty       = TextUtils.ToInt(item["F7"].ToString());
                            linkModel.VatLieu   = item["F8"].ToString();
                            linkModel.Weight    = TextUtils.ToDecimal(item["F9"].ToString());
                            linkModel.Hang      = item["F10"].ToString();

                            try
                            {
                                ArrayList     listMaterial = MaterialBO.Instance.FindByAttribute("Code", linkModel.Code);
                                MaterialModel model        = (MaterialModel)listMaterial[0];
                                linkModel.Price    = model.Price;
                                linkModel.Delivery = model.DeliveryPeriod;
                            }
                            catch (Exception)
                            {
                                linkModel.Price    = 0;
                                linkModel.Delivery = 0;
                            }

                            MaterialModuleLinkBO.Instance.Insert(linkModel);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    #endregion TẠO DANH MỤC VẬT TƯ CHO MODULE
                }
            }
        }
Пример #15
0
        /// <summary>
        /// Phân bổ dữ liệu cho phòng kế toán
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {
            DocUtils.InitFTPQLSX();
            string    _productCode  = "TPAD.A2106";
            string    _projectCode  = "DA1";
            string    _serverPathCK = "Thietke.Ck/" + _productCode.Substring(0, 6) + "/" + _productCode + ".Ck/";
            DataTable dt            = TextUtils.Select("vPBDL_Structure_File", new Expression("DepartmentID", 8));
            ArrayList listStruc     = PBDLStructureBO.Instance.FindByAttribute("DepartmentID", 8);

            if (listStruc.Count > 0)
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    string initPath = fbd.SelectedPath;

                    #region Lấy dữ liệu trong file danh mục vật tư cơ khí
                    try
                    {
                        if (DocUtils.CheckExits(_serverPathCK + "/VT." + _productCode + ".xlsm"))
                        {
                            //Download file danh mục vật tư
                            DocUtils.DownloadFile(initPath, "VT." + _productCode + ".xlsm", _serverPathCK + "/VT." + _productCode + ".xlsm");
                        }
                    }
                    catch
                    {
                    }

                    string    pathDMVT = initPath + "/VT." + _productCode + ".xlsm";
                    DataTable dtDMVT   = TextUtils.ExcelToDatatable(pathDMVT, "DMVT");

                    for (int i = 0; i <= 4; i++)
                    {
                        dtDMVT.Rows.RemoveAt(0);
                    }
                    File.Delete(pathDMVT);

                    #endregion

                    foreach (var item in listStruc)
                    {
                        PBDLStructureModel strucModel = (PBDLStructureModel)item;
                        string             pathStruc  = strucModel.Path.Replace("project", _projectCode).Replace("code", _productCode);
                        string             pathLocal  = initPath + "/" + pathStruc;
                        Directory.CreateDirectory(pathLocal);
                        DataTable dtFile = TextUtils.Select("vPBDL_Structure_File", new Expression("PBDLStructureID", strucModel.ID));
                        foreach (DataRow row in dtFile.Rows)
                        {
                            int           pBDLFileID = TextUtils.ToInt(row["PBDLFileID"]);
                            PBDLFileModel fileModel  = (PBDLFileModel)PBDLFileBO.Instance.FindByPK(pBDLFileID);

                            if (fileModel.GetType == 0)//nhieu file
                            {
                                string pathServer = fileModel.FolderContain.Replace("group", _productCode.Substring(0, 6)).Replace("code", _productCode);

                                #region Mã vật liệu
                                if (fileModel.FilterMaVatLieu)//nếu có mã vật liệu
                                {
                                    DataRow[] listMaVatLieu = dtDMVT.Select("F5 <> '' and F4 like '%TPAD%' ");
                                    foreach (DataRow rowMVL in listMaVatLieu)
                                    {
                                        string fileName = rowMVL["F4"].ToString();
                                        try
                                        {
                                            if (DocUtils.CheckExits(pathServer + "/" + fileName + ".dwg"))
                                            {
                                                DocUtils.DownloadFile(pathLocal, fileName + fileModel.Extension, pathServer + "/" + fileName + fileModel.Extension);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                #endregion

                                #region Đơn vị
                                if (fileModel.FilterDonVi != "")
                                {
                                    DataRow[] listDonVi = dtDMVT.Select("F6 like '%" + fileModel.FilterDonVi.ToUpper() + "%' and F4 like '%TPAD%' ");
                                    foreach (DataRow rowMVL in listDonVi)
                                    {
                                        string fileName = rowMVL["F4"].ToString();
                                        try
                                        {
                                            if (DocUtils.CheckExits(pathServer + "/" + fileName + ".dwg"))
                                            {
                                                DocUtils.DownloadFile(pathLocal, fileName + fileModel.Extension, pathServer + "/" + fileName + fileModel.Extension);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                #endregion Đơn vị

                                #region Thông Số
                                if (fileModel.FilterThongSo != "")
                                {
                                    DataRow[] listThongSo = dtDMVT.Select("F3 like '%" + fileModel.FilterThongSo.ToUpper() + "%' and F4 like '%TPAD%' ");
                                    foreach (DataRow rowThongSo in listThongSo)
                                    {
                                        string fileName = rowThongSo["F4"].ToString();
                                        try
                                        {
                                            if (DocUtils.CheckExits(pathServer + "/" + fileName + ".dwg"))
                                            {
                                                DocUtils.DownloadFile(pathLocal, fileName + fileModel.Extension, pathServer + "/" + fileName + fileModel.Extension);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                #endregion Thông Số

                                #region MẶT
                                if (fileModel.MAT)
                                {
                                    try
                                    {
                                        string[] listFileMat = DocUtils.GetFilesList(pathServer);
                                        if (listFileMat != null)
                                        {
                                            foreach (string fileName in listFileMat)
                                            {
                                                try
                                                {
                                                    if (DocUtils.CheckExits(pathServer + "/" + fileName))
                                                    {
                                                        DocUtils.DownloadFile(pathLocal, fileName, pathServer + "/" + fileName);
                                                    }
                                                }
                                                catch
                                                {
                                                }
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                #endregion Mặt

                                #region TEM
                                if (fileModel.TEM)
                                {
                                    try
                                    {
                                        string[] listFileTEM = DocUtils.GetFilesList(pathServer);
                                        if (listFileTEM != null)
                                        {
                                            foreach (string fileName in listFileTEM)
                                            {
                                                try
                                                {
                                                    if (DocUtils.CheckExits(pathServer + "/" + fileName))
                                                    {
                                                        DocUtils.DownloadFile(pathLocal, fileName, pathServer + "/" + fileName);
                                                    }
                                                }
                                                catch
                                                {
                                                }
                                            }
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                #endregion TEM
                            }
                            else//1 file
                            {
                                if (strucModel.FolderType != 2)//nếu không phải là thư mục điện tử
                                {
                                    string filePathServer = fileModel.FolderContain.Replace("group", _productCode.Substring(0, 6)).Replace("code", _productCode);
                                    try
                                    {
                                        if (DocUtils.CheckExits(filePathServer))
                                        {
                                            DocUtils.DownloadFile(pathLocal, Path.GetFileName(filePathServer), filePathServer);
                                        }
                                    }
                                    catch
                                    {
                                    }
                                }
                                else
                                {
                                    DataRow[] listPCB = dtDMVT.Select("F4 like '%PCB%'");
                                    foreach (DataRow rowDT in listPCB)
                                    {
                                        string pcbCode = rowDT["F4"].ToString();
                                        string pathPCB = pathLocal + "/" + pcbCode;
                                        if (pathPCB == "")
                                        {
                                            continue;
                                        }
                                        Directory.CreateDirectory(pathPCB);

                                        string filePathServer = fileModel.FolderContain.Replace("tpat", "TPAT." + pcbCode.Substring(4, 7)).Replace("code", pcbCode);
                                        try
                                        {
                                            if (DocUtils.CheckExits(filePathServer))
                                            {
                                                DocUtils.DownloadFile(pathPCB, Path.GetFileName(filePathServer), filePathServer);
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }