Exemplo n.º 1
0
        private string Readtxtfile()
        {
            //DataSet ds = new DataSet();

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = "选择工单料表";
            ofd.Filter = "(*.txt)|*.txt";
            DialogResult dlr = ofd.ShowDialog();

            if (dlr == DialogResult.Yes || dlr == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(ofd.FileName, Encoding.Default);
                string       line;
                int          i  = 0;
                DataTable    dt = new DataTable("mydt");
                dt.Columns.Add("生产工单号", System.Type.GetType("System.String"));
                dt.Columns.Add("成品料号", System.Type.GetType("System.String"));
                dt.Columns.Add("组件料号", System.Type.GetType("System.String"));
                dt.Columns.Add("组件物料描述", System.Type.GetType("System.String"));
                dt.Columns.Add("数量", System.Type.GetType("System.String"));
                dt.Columns.Add("制程段", System.Type.GetType("System.String"));
                while ((line = sr.ReadLine()) != null)
                {
                    i++;
                    if (i > 6)
                    {
                        if (line.IndexOf("----------------------") == -1)
                        {
                            string[] arr = line.Split('|');
                            dt.Rows.Add(arr[1], arr[2], arr[5], arr[6], arr[8], arr[11]);
                        }
                    }
                }
                ClsAllExcel cs = new ClsAllExcel();

                int    len           = (System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFile").Length + 1;
                string filename      = Path.GetFileName(ofd.FileName).Split('.')[0];
                string excelfilename = string.Empty;
                //System.IO.Directory.GetCurrentDirectory()+ "\\ConvertFileOK" + "\\"+filename+".xls"
                if (File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFileOK\\" + filename + ".xls"))
                {
                    //如果存在则删除
                    File.Delete(System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFileOK\\" + filename + ".xls");
                }
                cs.ExportExcel(dt, excelfilename = System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFileOK\\" + filename + ".xls", dt.Rows[1][0].ToString().Trim() + "-" + dt.Rows[1][1].ToString().Trim() + "-A");
                sr.Close();
                string err = string.Empty;
                if (string.IsNullOrEmpty(err = BomInfoToDB(excelfilename)))
                {
                    return(string.Empty);
                }
                else
                {
                    return(err);
                }
            }
            return("没有打开备料表文件");
        }
Exemplo n.º 2
0
        private void Readtxtfile()
        {
            List <string> lst = new List <string>();

            lst = GetFileName();
            this.mFrm.ShowPrgMsg(string.Format("共[{0}]个工单需要导入系统.", lst.Count), MainParent.MsgType.Warning);
            if (lst.Count != 0)
            {
                for (int x = 0; x < lst.Count; x++)
                {
                    this.mFrm.ShowPrgMsg(string.Format("正在处理第[{0}]个工单..", x + 1), MainParent.MsgType.Warning);
                    StreamReader sr = new StreamReader(lst[x], Encoding.Default);
                    string       line;
                    int          i  = 0;
                    DataTable    dt = new DataTable("mydt");
                    dt.Columns.Add("生产工单号", System.Type.GetType("System.String"));
                    dt.Columns.Add("成品料号", System.Type.GetType("System.String"));
                    dt.Columns.Add("组件料号", System.Type.GetType("System.String"));
                    dt.Columns.Add("组件物料描述", System.Type.GetType("System.String"));
                    dt.Columns.Add("数量", System.Type.GetType("System.String"));
                    dt.Columns.Add("制程段", System.Type.GetType("System.String"));
                    while ((line = sr.ReadLine()) != null)
                    {
                        i++;
                        if (i > 6)
                        {
                            if (line.IndexOf("----------------------") == -1)
                            {
                                string[] arr = line.Split('|');
                                dt.Rows.Add(arr[1], arr[2], arr[5], arr[6], arr[8], arr[11]);
                            }
                        }
                    }
                    ClsAllExcel cs       = new ClsAllExcel();
                    int         len      = (System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFile").Length + 1;
                    string      filename = lst[x].Substring(len, lst[x].Length - len);
                    filename = filename.Substring(0, filename.Length - 4);
                    cs.ExportExcel(dt, System.AppDomain.CurrentDomain.BaseDirectory + "ConvertFileOK\\" + filename + ".xls", dt.Rows[1][0].ToString().Trim() + "-" + dt.Rows[1][1].ToString().Trim() + "-A");
                    sr.Close();
                    if (File.Exists(lst[x]))
                    {
                        File.Delete(lst[x]);
                    }
                }
                this.mFrm.ShowPrgMsg("处理完成..", MainParent.MsgType.Incoming);
            }
        }
Exemplo n.º 3
0
        public void PrintForTable(string userId, DataTable _datatable, string machineId, string filepath)
        {//传进来的datatable需要进过排序
            ClsAllExcel excel = new ClsAllExcel();

            if (System.IO.Directory.Exists(filepath))
            {
                if (!System.IO.File.Exists(string.Format(@"{0}\print.xlt", filepath)))
                {
                    mFrm.ShowPrgMsg("模板没有找到,正在从Ftp下载..", MainParent.MsgType.Warning);
                    FrmBLL.Ftp_MyFtp ftp = new FrmBLL.Ftp_MyFtp();
                    ftp.DownloadFile("print.xlt", System.AppDomain.CurrentDomain.BaseDirectory + "excel", "print.xlt");
                    mFrm.ShowPrgMsg("下载完成", MainParent.MsgType.Outgoing);

                    //throw new Exception("备料表打印模板文件不存在");
                }
            }
            else
            {
                throw new Exception("打印模板文件路错误(请在程序运行目录下建立\"Excel\"文件夹");
            }
            excel.OpenFileName = string.Format(@"{0}\print.xlt", filepath);// :"D:\BOM\New\print.xlt";
            excel.OpenExcelFile();
            int rowindex = 10;

            excel.setOneCellValue(2, 6, string.Format("*{0} {1}*",
                                                      _datatable.Rows[0]["masterId"].ToString(), _datatable.Rows[0]["woId"].ToString()));
            excel.setOneCellValue(3, 6, string.Format("{0} {1}",
                                                      _datatable.Rows[0]["masterId"].ToString(), _datatable.Rows[0]["woId"].ToString()));
            excel.setOneCellValue(3, 2, _datatable.Rows[0]["woId"].ToString());
            excel.setOneCellValue(3, 3, _datatable.Rows[0]["modelname"].ToString());
            excel.setOneCellValue(4, 2, _datatable.Rows[0]["partnumber"].ToString());
            excel.setOneCellValue(4, 4, _datatable.Rows.Count.ToString());
            excel.setOneCellValue(5, 4, _datatable.Rows[0]["side"].ToString());
            excel.setOneCellValue(6, 4, _datatable.Rows[0]["bomver"].ToString());

            excel.setOneCellValue(5, 9, userId);
            excel.setOneCellValue(6, 9, FrmBLL.ReleaseData.arrByteToDataTable(refWebtUserInfo.Instance.GetUserInfo(userId, null, null)).Rows[0]["username"].ToString());

            excel.setOneCellValue(5, 6, this.sEditUser);
            if (!string.IsNullOrEmpty(this.sEditUser))
            {
                excel.setOneCellValue(6, 6, FrmBLL.ReleaseData.arrByteToDataTable(refWebtUserInfo.Instance.GetUserInfo(this.sEditUser, null, null)).Rows[0]["username"].ToString());
            }
            excel.setOneCellValue(5, 7, this.sCheckedUser);
            if (!string.IsNullOrEmpty(this.sCheckedUser))
            {
                excel.setOneCellValue(6, 7, FrmBLL.ReleaseData.arrByteToDataTable(refWebtUserInfo.Instance.GetUserInfo(this.sCheckedUser, null, null)).Rows[0]["username"].ToString());
            }
            excel.setOneCellValue(6, 2, machineId);

            for (int z = 0; z < _datatable.Rows.Count; z++)// (DataRow dr in _datatable.Rows)
            {
                excel.setOneCellValue(rowindex, 1, _datatable.Rows[z]["stationno"].ToString());
                excel.setOneCellValue(rowindex, 2, _datatable.Rows[z]["kpnumber"].ToString());
                excel.setOneCellValue(rowindex, 3, _datatable.Rows[z]["kpdesc"].ToString());
                excel.setOneCellValue(rowindex, 10, _datatable.Rows[z]["feedertype"].ToString());

                string[] arrStr = getstring(_datatable.Rows[z]["localtion"].ToString().Split(','), 4).Split('|');
                for (int y = 0; y < arrStr.Length; y++)
                {
                    if (!string.IsNullOrEmpty(arrStr[y]))
                    {
                        excel.setOneCellValue(rowindex, 6, arrStr[y]);
                        rowindex++;
                    }
                }

                if (!(z + 1 == _datatable.Rows.Count))
                {
                    //料站相同但是物料组不同的
                    if ((_datatable.Rows[z]["stationno"].ToString().ToUpper() == _datatable.Rows[z + 1]["stationno"].ToString().ToUpper()) &&
                        ((string.IsNullOrEmpty(_datatable.Rows[z]["replacegroup"].ToString().ToUpper()) ? "A" : _datatable.Rows[z]["replacegroup"].ToString().ToUpper()) !=
                         (string.IsNullOrEmpty(_datatable.Rows[z + 1]["replacegroup"].ToString().ToUpper()) ? "B" : _datatable.Rows[z + 1]["replacegroup"].ToString().ToUpper())))
                    {
                        throw new Exception(string.Format("物料替代关系错误:{0}与{1}不存在替代关系,或料站表制作有误.请检查",
                                                          _datatable.Rows[z]["kpnumber"].ToString(), _datatable.Rows[z + 1]["kpnumber"].ToString()));
                    }

                    if (_datatable.Rows[z]["stationno"].ToString().ToUpper() == _datatable.Rows[z + 1]["stationno"].ToString().ToUpper() &&
                        _datatable.Rows[z]["replacegroup"].ToString().ToUpper() == _datatable.Rows[z + 1]["replacegroup"].ToString().ToUpper())
                    {
                        excel.setOneCellValue(rowindex, 2, _datatable.Rows[z + 1]["kpnumber"].ToString());
                        excel.setOneCellValue(rowindex, 3, _datatable.Rows[z + 1]["kpdesc"].ToString());
                        rowindex++;
                        z++;
                    }
                }

                excel.setOneCellValue(rowindex, 1, "----------------------------------------------------------------------------------------------------------------------------------------------");
                rowindex++;
            }

            excel.SaveFileName = string.Format(@"{2}\{0}_{1}.xls", _datatable.Rows[0]["woId"].ToString(), machineId, filepath);
            excel.SaveAsExcel(true);
            excel.CloseExcelApplication();
        }