Example #1
0
        public static ImportTemplate getTemplate(string tmpName, string type)
        {
            ImportTemplate tmp;

            string[] files = Directory.GetFiles(BasePath, type + "_" + tmpName);
            if (files.Length == 0)
            {
                tmp = new ImportTemplate()
                {
                    FirstRowNum = 0, HasHeadColumn = true, Type = type, Name = "新建模板"
                };
            }
            else
            {
                BinaryFormatter formmatter = new BinaryFormatter();
                Byte[]          bytesobject;
                using (FileStream sw = new FileStream(files[0], FileMode.Open, FileAccess.Read))
                {
                    bytesobject = new byte[sw.Length];
                    int rl = sw.Read(bytesobject, 0, (int)sw.Length);
                }
                MemoryStream stream = new MemoryStream(bytesobject);
                tmp = formmatter.Deserialize(stream) as ImportTemplate;
            }
            return(tmp);
        }
Example #2
0
 public ExcelImport(string filename, string ztname, int zid, string type, ImportTemplate temp)
     : base(filename, ztname, zid)
 {
     this.Template = temp;
     this.Type = (DataType)Enum.Parse(typeof(DataType), type);
     dt = ExcelLib.NPOIHelper.Excel2DataTable(Filename, Template.HasHeadColumn, 1, Template.FirstRowNum);
 }
Example #3
0
        public ExcelProView(string ExcelFileName, string tmpName, string type, string id)
            : this()
        {
            tmp = TemplateHelper.getTemplate(tmpName, type);
            tmp.Id = id;
            this.FileName = ExcelFileName;
            this.TmpName = tmpName;
            this.chkfirstrowiscolname.Checked = tmp.HasHeadColumn;
            this.numFirstRow.Value = tmp.FirstRowNum;

            showTOP10Excel();
        }
Example #4
0
 public ExcelTemplate(ImportTemplate importtmp)
     : this()
 {
     this.tmp = importtmp;
     this.txtTemple.Text = tmp.Name;
     this.cmbType.Text = tmp.Type;
     if (tmp.Type.ToUpper() == "WPI")
     {
         chkWPI_AN.Checked = true;
         chkWPI_PN.Checked = true;
     }
     else if (tmp.Type.ToUpper() == "EPODOC")
     {
         chkEPO_AN.Checked = true;
         chkEPO_PN.Checked = true;
     }
 }
Example #5
0
 public static bool SaveTemplate(ImportTemplate tmp)
 {
     BinaryFormatter formmatter = new BinaryFormatter();
     MemoryStream stream = new MemoryStream();
     Byte[] bytesobject;
     formmatter.Serialize(stream, tmp);
     bytesobject = stream.ToArray();
     using (FileStream sw = new FileStream(BasePath + tmp.Type + "_" + tmp.Name, FileMode.OpenOrCreate, FileAccess.Write))
     {
         sw.Write(bytesobject, 0, bytesobject.Length);
     }
     if (tmp.Id != "0")
     {
         DBA.MySqlDbAccess.ExecNoQuery(System.Data.CommandType.Text, "update cfg_template set name='" + tmp.Name + "',dbtype='" + tmp.Type + "'  where id=" + tmp.Id);
     }
     else
     {
         DBA.MySqlDbAccess.ExecNoQuery(System.Data.CommandType.Text, "insert into cfg_template (name,dbtype,filetype,path)  values ('" + tmp.Name + "','" + tmp.Type + "','xls|xlsx','')");
     }
     log.Info("保存模板:" + tmp.Name + "\t" + DateTime.Now);
     return true;
 }
Example #6
0
 public static ImportTemplate getTemplate(string tmpName, string type)
 {
     ImportTemplate tmp;
     string[] files = Directory.GetFiles(BasePath, type + "_" + tmpName);
     if (files.Length == 0)
     {
         tmp = new ImportTemplate() { FirstRowNum = 0, HasHeadColumn = true, Type = type, Name = "新建模板" };
     }
     else
     {
         BinaryFormatter formmatter = new BinaryFormatter();
         Byte[] bytesobject;
         using (FileStream sw = new FileStream(files[0], FileMode.Open, FileAccess.Read))
         {
             bytesobject = new byte[sw.Length];
             int rl = sw.Read(bytesobject, 0, (int)sw.Length);
         }
         MemoryStream stream = new MemoryStream(bytesobject);
         tmp = formmatter.Deserialize(stream) as ImportTemplate;
     }
     return tmp;
 }
Example #7
0
        public static bool SaveTemplate(ImportTemplate tmp)
        {
            BinaryFormatter formmatter = new BinaryFormatter();
            MemoryStream    stream     = new MemoryStream();

            Byte[] bytesobject;
            formmatter.Serialize(stream, tmp);
            bytesobject = stream.ToArray();
            using (FileStream sw = new FileStream(BasePath + tmp.Type + "_" + tmp.Name, FileMode.OpenOrCreate, FileAccess.Write))
            {
                sw.Write(bytesobject, 0, bytesobject.Length);
            }
            if (tmp.Id != "0")
            {
                DBA.MySqlDbAccess.ExecNoQuery(System.Data.CommandType.Text, "update cfg_template set name='" + tmp.Name + "',dbtype='" + tmp.Type + "'  where id=" + tmp.Id);
            }
            else
            {
                DBA.MySqlDbAccess.ExecNoQuery(System.Data.CommandType.Text, "insert into cfg_template (name,dbtype,filetype,path)  values ('" + tmp.Name + "','" + tmp.Type + "','xls|xlsx','')");
            }
            log.Info("保存模板:" + tmp.Name + "\t" + DateTime.Now);
            return(true);
        }
Example #8
0
        private void list_template_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            if (e.RowIndex == -1) return;
            if (e.ColumnIndex == -1) return;
            ztinfo zt = (ztinfo)cmbZTList.SelectedItem;
            string type = zt.DbType;
            string id = this.dgwtemplate.Rows[e.RowIndex].Cells["Id"].Value.ToString();
            string tmpname = this.dgwtemplate.Rows[e.RowIndex].Cells["name"].Value.ToString();

            if (Path.GetExtension(this.txtFileName.Text.Trim()).IndexOf(".xls") >= 0)
            {
                ExcelProView ex = new ExcelProView(this.txtFileName.Text, tmpname, type, id);
                if (ex.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    this.tmplate = ex.tmp;
                    this.txtTemplate.Text = tmplate.Name;
                    this.panTemplate.Visible = false;
                }
            }
            else
            {
                this.txtTemplate.Text = tmpname;
                this.panTemplate.Visible = false;
            }
        }