Beispiel #1
0
        private void Button_Click_Out1(object sender, RoutedEventArgs e)
        {
            if (materialress == null || materialress.Count == 0)
            {
                MessageBox.Show("剩余原材料数据为空,无法导出");
                return;
            }
            DataTable dt = new DataTable();

            dt.Columns.Add("外径", Type.GetType("System.String"));
            dt.Columns.Add("壁厚", Type.GetType("System.String"));
            dt.Columns.Add("材质", Type.GetType("System.String"));
            dt.Columns.Add("等级", Type.GetType("System.String"));
            dt.Columns.Add("长度", Type.GetType("System.Int32"));
            dt.Columns.Add("炉批号", Type.GetType("System.String"));
            dt.Columns.Add("物料号", Type.GetType("System.String"));

            foreach (var outPut in materialress)
            {
                DataRow newRow = dt.NewRow();
                newRow["外径"]  = outPut.WaiJing;
                newRow["壁厚"]  = outPut.BiHou;
                newRow["材质"]  = outPut.CaiZhi;
                newRow["等级"]  = outPut.Dengji;
                newRow["长度"]  = outPut.length;
                newRow["炉批号"] = outPut.LuPiHao;
                newRow["物料号"] = outPut.WuLiaoHao;
                dt.Rows.Add(newRow);
            }

            string defaultName = "剩余原材料数据 " + DateTime.Now.ToString("yyyy-MM-dd HH-mm");

            SaveFileDialog sfd = new SaveFileDialog(); //设置文件类型

            sfd.Filter   = "导出数据(*.csv)|*.csv";
            sfd.FileName = defaultName;
            //设置默认文件类型显示顺序
            //sfd.FilterIndex = 1;

            //保存对话框是否记忆上次打开的目录
            sfd.RestoreDirectory = true;

            //点了保存按钮进入
            if (sfd.ShowDialog() == true)
            {
                string localFilePath = sfd.FileName.ToString();                                      //获得文件路径+文件名
                string fileNameExt   = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
                                                                                                     //获取文件路径,不带文件名
                string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));

                //保存
                cSVFile.ExportToSvc(dt, FilePath, fileNameExt);
            }
        }
Beispiel #2
0
        public void savefile(List <OutPutValue> outlist)
        {
            if (outlist == null || outlist.Count == 0)
            {
                MessageBox.Show("切割尺寸为空,无法导出");
                return;
            }
            DataTable dt = new DataTable();

            dt.Columns.Add("等级", Type.GetType("System.String"));
            dt.Columns.Add("材质", Type.GetType("System.String"));
            dt.Columns.Add("管径", Type.GetType("System.String"));
            dt.Columns.Add("壁厚", Type.GetType("System.String"));
            dt.Columns.Add("原材料长", Type.GetType("System.Int32"));
            var count = outlist.Select(a => a.productList.Count).ToList().Max();

            for (int index = 1; index <= 15; index++)
            {
                dt.Columns.Add("段长" + index, Type.GetType("System.Int32"));
            }
            dt.Columns.Add("END", Type.GetType("System.String"));

            foreach (OutPutValue outPut in outlist)
            {
                DataRow newRow = dt.NewRow();
                newRow["等级"]   = outPut.material.Dengji;
                newRow["材质"]   = outPut.material.CaiZhi;
                newRow["管径"]   = outPut.material.WaiJing;
                newRow["壁厚"]   = outPut.material.BiHou;
                newRow["原材料长"] = outPut.material.length;
                for (int j = 0; j < outPut.productList.Count; j++)
                {
                    int index = j + 1;
                    newRow["段长" + index] = outPut.productList[j].length;
                }
                dt.Rows.Add(newRow);
            }

            string defaultName = "切割计划PLC数据 " + DateTime.Now.ToString("yyyy-MM-dd HH-mm");

            SaveFileDialog sfd = new SaveFileDialog(); //设置文件类型

            sfd.Filter   = "导出数据(*.csv)|*.csv";
            sfd.FileName = defaultName;
            //设置默认文件类型显示顺序
            //sfd.FilterIndex = 1;

            //保存对话框是否记忆上次打开的目录
            sfd.RestoreDirectory = true;

            //点了保存按钮进入
            if (sfd.ShowDialog() == true)
            {
                string localFilePath = sfd.FileName.ToString();                                      //获得文件路径+文件名
                string fileNameExt   = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
                                                                                                     //获取文件路径,不带文件名
                string FilePath = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));

                //保存
                cSVFile.ExportToSvc(dt, FilePath, fileNameExt);
            }
        }