示例#1
0
        private void outputFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string folder = Properties.Settings.Default.outputFolder;

            if (folder == string.Empty)
            {
                folder = Application.StartupPath + @"\Output";
            }
            Form         form   = new folderSelector(this, folder);
            DialogResult result = form.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            using (FolderBrowserDialog folderDialog = new FolderBrowserDialog())
            {
                //folderDialog.SelectedPath = outputFolder;
                folderDialog.SelectedPath = searchFolder;

                if (folderDialog.ShowDialog() == DialogResult.OK)
                {
                    outputFolder = folderDialog.SelectedPath;
                    Properties.Settings.Default.outputFolder = outputFolder;
                    Properties.Settings.Default.Save();
                }
            }
        }
示例#2
0
        private void configFileToolStripMenuItem_Click(object sender, EventArgs e)

        {
            string folder = Properties.Settings.Default.configFolder;

            if (folder == string.Empty)
            {
                folder = Application.StartupPath + @"\Config";
            }
            Form form = new folderSelector(this, folder);

            DialogResult result = form.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            string filePath = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = searchFolder == "" ? Application.StartupPath : searchFolder;
                openFileDialog.Filter           = "CSV files (*.csv)|*.json|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;


                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = openFileDialog.FileName;
                    int    i            = filePath.LastIndexOf('\\');
                    string configFolder = filePath.Substring(0, i);

                    Properties.Settings.Default.configFolder = configFolder;
                    Properties.Settings.Default.Save();


                    Configs = new List <Config>();


                    Workbook wb = null;
                    using (FileStream fs = new FileStream(filePath, FileMode.Open))
                    {
                        wb = Workbook.Load(fs);
                        Worksheet ws   = wb.CurrentWorksheet;
                        int       rows = ws.GetLastRowNumber();

                        for (int row = 1; row <= rows; row++)
                        {
                            Config config = new Config();
                            config.SKU            = (string)ws.GetCell(0, row).Value;
                            config.FulfillmentSKU = (string)ws.GetCell(1, row).Value;
                            config.ImageType      = (string)ws.GetCell(2, row).Value;
                            if (config.ImageType == "IMAGE-ONLY")
                            {
                                config.SourceImage = (string)ws.GetCell(3, row).Value;
                            }
                            else
                            {
                                config.SourceImage = "";
                            }

                            config.Width  = int.Parse(ws.GetCell(4, row).Value.ToString());
                            config.Height = int.Parse(ws.GetCell(5, row).Value.ToString());

                            try { config.C1_StartX = int.Parse(ws.GetCell(6, row).Value.ToString()); }
                            catch { config.C1_StartX = null; }

                            try { config.C1_StartY = int.Parse(ws.GetCell(7, row).Value.ToString()); }
                            catch { config.C1_StartY = null; }

                            try { config.C1_Width = int.Parse(ws.GetCell(8, row).Value.ToString()); }
                            catch { config.C1_Width = null; }

                            try { config.C1_Height = int.Parse(ws.GetCell(9, row).Value.ToString()); }
                            catch { config.C1_Height = null; }

                            try { config.C2_StartX = int.Parse(ws.GetCell(10, row).Value.ToString()); }
                            catch { config.C2_StartX = null; }

                            try { config.C2_StartY = int.Parse(ws.GetCell(11, row).Value.ToString()); }
                            catch { config.C2_StartY = null; }

                            try { config.C2_Width = int.Parse(ws.GetCell(12, row).Value.ToString()); }
                            catch { config.C2_Width = null; }

                            try { config.C2_Height = int.Parse(ws.GetCell(13, row).Value.ToString()); }
                            catch { config.C2_Height = null; }

                            Configs.Add(config);
                        }
                    }
                }
            }
        }