/// <summary>
        /// folder open funcion
        /// </summary>
        /// <param name="sender,e"></param>
        private void btnForderOpen_Click(object sender, EventArgs e)
        {
            mme.fields    = "Char1,Char2";
            mme.tableName = "M_MultiPorpose";
            mme.condition = "Where ID=116 And [Key]='1'";
            DataTable dt = psks0103ibl.M_MultiPorpose_DynamicSelect(mme);

            if (dt.Rows.Count > 0)
            {
                folderPath = dt.Rows[0]["Char2"].ToString();
                fileName   = dt.Rows[0]["Char1"].ToString();
            }
            OpenFileDialog dlog = new OpenFileDialog();

            dlog.Filter           = "TXT|*.txt";
            dlog.InitialDirectory = folderPath;
            if (!string.IsNullOrWhiteSpace(folderPath))
            {
                if (!Directory.Exists(folderPath))
                {
                    try
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    catch
                    {
                        string newPath = @"C:\";
                        dlog.InitialDirectory = newPath;
                        Directory.CreateDirectory(newPath);
                    }
                }
            }
            if (dlog.ShowDialog() == DialogResult.OK)
            {
                txtfilepath.Text      = dlog.FileName;
                txtfilepath.BackColor = Color.White;

                // update new path in multiporpose table
                string folder = txtfilepath.Text.Remove(txtfilepath.Text.LastIndexOf('\\'));
                mme.fields    = Path.GetFileName(txtfilepath.Text) + "," + folder;
                mme.tableName = "M_MultiPorpose";
                mme.condition = " Where ID=116 And [Key]='1'";

                var data = psks0103ibl.M_MultiPorpose_DynamicUpdateData(mme);
            }
        }
        private void frmPSKS0103I_Load(object sender, EventArgs e)
        {
            FunctionButtonDisabled(2);
            FunctionButtonDisabled(3);
            FunctionButtonDisabled(4);
            FunctionButtonDisabled(5);
            FunctionButtonDisabled(7);
            FunctionButtonDisabled(8);
            FunctionButtonDisabled(10);
            FunctionButtonDisabled(11);

            pskso116ibl          = new PSKS0116I_BL();
            psks0103ibl          = new PSKS0103I_BL();
            ucSupplier.GotFocus += new System.EventHandler(ucSupplier_GotFocus);

            FormName = "メーカー在庫取込";

            lblMode.Visible   = true;
            lblMode.Text      = "先に通常取込を実施してください";
            lblMode.BackColor = Color.FromArgb(255, 102, 255);
            lblMode.Width     = 250;
            lblMode.TextAlign = ContentAlignment.MiddleCenter;

            btnImport.Enabled = false;
            FunctionButtonDisabled(12);

            mme           = new M_MultiPorpose_Entity();
            mme.fields    = "Char1,Num1";
            mme.tableName = "M_MultiPorpose";
            mme.condition = "Where ID=101 And [Key]='1'";

            DataTable dt = psks0103ibl.M_MultiPorpose_DynamicSelect(mme);

            if (dt.Rows.Count > 0)
            {
                lblServerPath.Text = "サーバーの" + dt.Rows[0]["Char1"].ToString() + "フォルダーに保存されているファイルを取込します。";
                lblHistory.Text    = dt.Rows[0]["Num1"] + "日間の履歴を保持しています";
                folderPath         = dt.Rows[0]["Char1"].ToString();
            }

            dgvImportRireki.DisabledColumn("colNo1,colInportDateTime,colDataMoto,colInportFile,colInportOperator,colInportSu,colErrorSu");
            dgvFileDetail.DisabledColumn("*");

            tmire = new T_MakerInportRireki_Entity();
            DataTable dtInport = psks0103ibl.T_MakerInportRireki_SELECT(tmire);

            dgvImportRireki.DataSource = dtInport;
        }
Exemplo n.º 3
0
        public bool InsertData(int i)
        {
            try
            {
                dgv1.Rows[i].Cells["colStatus"].Value          = "Importing.....";
                dgv1.Rows[i].Cells["colImage"].Value           = SMS.Properties.Resources.dbImport;
                dgv1.Rows[i].Cells["colImage"].Style.BackColor = Color.FromArgb(255, 255, 192);


                string filePath = dgv1.Rows[i].Cells["colFileName"].Value.ToString();
                string ext      = Path.GetExtension(filePath);

                DataTable dtImport = new DataTable();

                mzde           = new MakerZaiko_D_Entity();
                mzde.PatternCD = patternCD;
                DataTable dtPattern = psks0103ibl.M_MakerZaiko_D_Select(mzde);

                if (ext.Equals(".csv"))
                {
                    if (patternCD == "011") /// for sankyo_ maker by etz
                    {
                        dtImport = CSVToTable(filePath, dtPattern.Rows.Count);
                    }
                    else
                    {
                        dtImport = CSVToTable(filePath);
                    }
                }
                else if (ext.Equals(".xlsx") || ext.Equals(".xls"))
                {
                    dtImport = ExcelToDatatable(filePath);
                }
                else
                {
                    dgv1.Rows[i].Cells["colStatus"].Value          = "Invalid File";
                    dgv1.Rows[i].Cells["colImage"].Value           = SMS.Properties.Resources.close;
                    dgv1.Rows[i].Cells["colImage"].Style.BackColor = Color.Red;
                    return(false);
                }

                //Delete Extra Column With Blank Rows   ---ktp 2019-04-16
                ArrayList arrdatacolumn = new ArrayList();

                string Keys = "MaungPhyoeGyi_JennieKim";      // -------PTK Added Use-header row Conflict
                if (!CheckAllPhyoeGyiColumns(dtImport, Keys)) /// PTK Added For Use-header row Conflict
                {
                    foreach (DataColumn dc in dtImport.Columns)
                    {
                        if (dc.ColumnName.Contains(Keys))
                        {
                            arrdatacolumn.Add(dc);
                        }
                    }

                    foreach (DataColumn dc in arrdatacolumn)
                    {
                        dtImport.Columns.Remove(dc);
                    }
                }
                dtImport.AcceptChanges();
                try
                {
                    M_MultiPorpose_Entity mme1 = new M_MultiPorpose_Entity();
                    mme1.fields    = "Char1,Num1,Char5";
                    mme1.tableName = "M_MultiPorpose";
                    mme1.condition = "Where ID=101 And [Key]='1'";

                    DataTable dt1 = psks0103ibl.M_MultiPorpose_DynamicSelect(mme1);
                    if (dt1.Rows[0]["Char5"].ToString() == "1")
                    {
                        MessageBox.Show("Excel cols " + dtImport.Columns.Count.ToString() + Environment.NewLine + "Pattern Cols" + dtPattern.Rows.Count.ToString());
                    }
                }
                catch { }
                if (dtImport.Columns.Count != dtPattern.Rows.Count)
                {
                    DSP_MSG("E137", string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);
                    dgv1.Rows[i].Cells["colStatus"].Value          = "Failed";
                    dgv1.Rows[i].Cells["colImage"].Value           = SMS.Properties.Resources.Failed;
                    dgv1.Rows[i].Cells["colImage"].Style.BackColor = Color.Red;

                    return(false);
                }

                tmze.dt1            = dtImport;
                tmze.ImportFileName = Path.GetFileName(filePath);

                M_MultiPorpose_Entity mme = new M_MultiPorpose_Entity();
                mme.fields    = "Char1,Char2,Num1";
                mme.tableName = "M_MultiPorpose";
                mme.condition = "Where ID=101 And [Key]='1'";

                DataTable dt = psks0103ibl.M_MultiPorpose_DynamicSelect(mme);

                //string destination = @"C:\SMS\PSKS0103I\ImportFinished\";

                string destination = String.IsNullOrEmpty(dt.Rows[0]["Char2"].ToString()) ? @"C:\SMS\PSKS0103I\ImportFinished\" : dt.Rows[0]["Char2"].ToString() + @"\";

                if (psks0103ibl.ImportProcess(tmze, patternCD, dtPattern, i, System.DateTime.Now.ToString()))
                {
                    dgv1.Rows[i].Cells["colStatus"].Value          = "Finished";
                    dgv1.Rows[i].Cells["colImage"].Value           = SMS.Properties.Resources.success;
                    dgv1.Rows[i].Cells["colImage"].Style.BackColor = Color.FromArgb(192, 255, 192);
                    if (!Directory.Exists(destination))
                    {
                        Directory.CreateDirectory(destination);
                    }

                    if (File.Exists(destination + Path.GetFileName(filePath)))
                    {
                        File.Delete(destination + Path.GetFileName(filePath));
                    }
                    try
                    {
                        File.Move(filePath, destination + Path.GetFileName(filePath));
                    }
                    catch { };
                }
                else
                {
                    dgv1.Rows[i].Cells["colStatus"].Value          = "Failed";
                    dgv1.Rows[i].Cells["colImage"].Value           = SMS.Properties.Resources.close;
                    dgv1.Rows[i].Cells["colImage"].Style.BackColor = Color.Red;
                }

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.ToString());
                return(false);
            }
        }