Esempio n. 1
0
        private void dgv_Data_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int    rowindex    = e.RowIndex;
            int    columnindex = e.ColumnIndex;
            string id          = dgv_Data.Rows[rowindex].Cells["ID"].Value.ToString();

            if (columnindex == 0) //编辑
            {
                lb_ID.Text      = id;
                tb_Code.Text    = dgv_Data.Rows[rowindex].Cells["Code"].Value.ToString();
                tb_Title.Text   = dgv_Data.Rows[rowindex].Cells["Title"].Value.ToString();
                tb_Remark.Text  = dgv_Data.Rows[rowindex].Cells["Remark"].Value.ToString();
                cb_Postfix.Text = dgv_Data.Rows[rowindex].Cells["Postfix"].Value.ToString();

                IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
                UpLoadFileInfo upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", int.Parse(id));
                if (upfInfo != null)
                {
                    string fpath   = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
                    string Content = Common.FileHandle.ReadFile(fpath);
                    textEditorControl.Text = Content;
                }
            }
            else if (columnindex == 1)  //删除
            {
                if (MessageBox.Show("确认删除?", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
                    UpLoadFileInfo upfInfo = new UpLoadFileInfo();
                    upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", int.Parse(id));
                    if (upfInfo != null && upfInfo.FileID != 0)
                    {
                        string fpath = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
                        Common.FileHandle.DeleteFile(fpath);
                        if (ufDal.UpLoadFile_Del(upfInfo.FileID) != 1)
                        {
                            MessageBox.Show("删除失败。");
                            return;
                        }
                    }

                    if (dal.Templet_Del(int.Parse(id)) == 1)
                    {
                        QueryData();
                        MessageBox.Show("删除成功。");
                    }
                    else
                    {
                        MessageBox.Show("删除失败。");
                    }
                }
            }
        }
        private string GetCodeByHtml(out string rstmsg)
        {
            rstmsg = "";
            string Content = "";
            string templet = "";

            IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
            UpLoadFileInfo upfInfo = new UpLoadFileInfo();

            upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", templetInfo.ID);
            string path = "";

            if (upfInfo != null && upfInfo.FileID != 0)
            {
                path = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
            }
            //获取模板
            templet = Common.FileHandle.ReadFile(path);
            Content = ReplaceLable(templet);


            return(Content);
        }
        private string GetCodeByXslt(out string rstmsg)
        {
            rstmsg = "";
            string Content = "";

            DataBaseInfo   info      = GetDbInfo(dinfo.DbLinkID);
            string         xml       = null;
            string         tablename = dinfo.Name;
            TableInfo      table     = null;
            DbDataTypeEnum ddt       = DbDataType.GetDbDataType(dinfo.NameType);

            switch (ddt)
            {
            case DbDataTypeEnum.表:
                table = info.Tables[tablename];
                break;

            case DbDataTypeEnum.视图:
                table = info.View[tablename];
                break;
            }

            if (table == null)
            {
                MessageBox.Show("获取数据失败。");
                return(Content);
            }
            try
            {
                #region 生成设置
                if (dgv_right.Rows.Count > 0)
                {
                    if (dgv_right.Rows[0].Cells["rName"].Value != null && dgv_right.Rows.Count != 1)
                    {
                        IList <FieldInfo> olist = table.Fields.GetList();
                        table.Fields.Clear();

                        for (int i = 0; i < dgv_right.Rows.Count; i++)
                        {
                            if (dgv_right.Rows[i].Cells["rName"].Value != null)
                            {
                                string name        = dgv_right.Rows[i].Cells["rName"].Value == null ? "" : dgv_right.Rows[i].Cells["rName"].Value.ToString().Trim();
                                string description = dgv_right.Rows[i].Cells["rDescription"].Value == null ? "" : dgv_right.Rows[i].Cells["rDescription"].Value.ToString().Trim();
                                string PrimaryKey  = dgv_right.Rows[i].Cells["rPrimaryKey"].Value == null ? "" : dgv_right.Rows[i].Cells["rPrimaryKey"].Value.ToString().Trim();
                                string IsIdentity  = dgv_right.Rows[i].Cells["rIsIdentity"].Value == null ? "" : dgv_right.Rows[i].Cells["rIsIdentity"].Value.ToString().Trim();
                                string Nullable    = dgv_right.Rows[i].Cells["rNullable"].Value == null ? "" : dgv_right.Rows[i].Cells["rNullable"].Value.ToString().Trim();
                                string FieldType   = dgv_right.Rows[i].Cells["rFieldType"].Value == null ? "" : dgv_right.Rows[i].Cells["rFieldType"].Value.ToString().Trim();

                                var wlist = olist.Where(t => t.Name == name).ToList();
                                if (wlist.Count > 0)
                                {
                                    var winfo = wlist[0];
                                    winfo.Description = description;
                                    table.Fields.Add(winfo);
                                }
                                else if (name != "")
                                {
                                    FieldInfo nfinfo = new FieldInfo();
                                    nfinfo.Name        = name;
                                    nfinfo.Description = description;
                                    nfinfo.PrimaryKey  = PrimaryKey == "" ? false : Convert.ToBoolean(PrimaryKey);
                                    nfinfo.IsIdentity  = IsIdentity == "" ? false : Convert.ToBoolean(IsIdentity);
                                    nfinfo.Nullable    = Nullable == "" ? false : Convert.ToBoolean(Nullable);
                                    nfinfo.FieldType   = FieldType;

                                    table.Fields.Add(nfinfo);
                                }
                            }
                        }
                    }
                }
                #endregion

                xml = GetXMLString(table);
            }
            catch (Exception ex)
            {
                MessageBox.Show("失败。" + ex.Message);
            }

            IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
            UpLoadFileInfo upfInfo = new UpLoadFileInfo();
            upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", templetInfo.ID);
            string path = "";
            if (upfInfo != null && upfInfo.FileID != 0)
            {
                path = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
            }

            //获取模板
            string templet    = Common.FileHandle.ReadFile(path);
            string strtemplet = ReplaceLable(templet);
            string fpath      = AppDomain.CurrentDomain.BaseDirectory + @"CodeMaker\Temp_" + upfInfo.UniqueName;
            //保存临时模板
            Common.FileHandle.WirteCreateFile(strtemplet, fpath);

            try
            {
                // 启动了XSLT模板,执行XSLT转换
                //System.Xml.Xsl.XslTransform transform = new System.Xml.Xsl.XslTransform();
                System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();
                transform.Load(fpath);
                System.IO.StringWriter writer = new System.IO.StringWriter();
                System.Xml.XmlDocument doc    = new System.Xml.XmlDocument();
                doc.LoadXml(xml);
                //transform.Transform(doc, null, writer, null);
                transform.Transform(doc, null, writer);
                writer.Close();
                Content = writer.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成失败," + ex.Message);
            }
            //删除临时模板
            Common.FileHandle.DeleteFile(fpath);

            //Content = ReplaceLable(Content);

            Content = Content.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "");
            Content = Content.Replace("&lt;", "<");
            Content = Content.Replace("&gt;", ">");

            Content = Content.Replace("&amp;", "&");
            return(Content);
        }
Esempio n. 4
0
        /// <summary>
        /// 保存数据
        /// </summary>
        private void SaveData()
        {
            TempletInfo info = new TempletInfo();

            info.Code    = tb_Code.Text.Trim();
            info.Title   = tb_Title.Text.Trim();
            info.Content = "";
            info.Remark  = tb_Remark.Text.Trim();
            info.Postfix = cb_Postfix.Text;
            info.Path    = "";
            string Content = textEditorControl.Text;

            if (ParentInfo == null && lb_ID.Text == "")
            {
                MessageBox.Show("请选择目录。");
                return;
            }
            if (info.Title == "")
            {
                MessageBox.Show("请输入名称。");
                return;
            }
            if (Content == "")
            {
                MessageBox.Show("请输入内容。");
                return;
            }
            if (info.Postfix == "")
            {
                MessageBox.Show("请选择后缀名称。");
                return;
            }

            int rst       = -1;
            int TempletID = 0;

            if (lb_ID.Text == "")
            {
                info.ParentID = ParentInfo.ID;
                rst           = dal.Templet_Add(info, out TempletID);
            }
            else
            {
                info.ID   = int.Parse(lb_ID.Text);
                TempletID = info.ID;
                rst       = dal.Templet_Edit(info);
            }

            if (rst == 1)
            {
                IUpLoadFile    ufDal   = new AccessDal.CodeMaker.UpLoadFile();
                UpLoadFileInfo upfInfo = new UpLoadFileInfo();

                upfInfo = ufDal.UpLoadFileGetInfo("Cm_Templet", TempletID);
                if (upfInfo != null && upfInfo.FileID != 0)
                {
                    string path = AppDomain.CurrentDomain.BaseDirectory + upfInfo.FilePath + "\\" + upfInfo.UniqueName;
                    Common.FileHandle.DeleteFile(path);
                    if (ufDal.UpLoadFile_Del(upfInfo.FileID) != 1)
                    {
                        MessageBox.Show("操作失败。");
                        return;
                    }
                }

                TempletInfo     tinfo    = dal.TempletGetInfo(TempletID);
                TempletTypeInfo tltinfo  = menuDal.TempletTypeGetInfo(tinfo.ParentID);
                string          fpath    = CodeFile.GetFilePath(tltinfo);
                string          filepath = AppDomain.CurrentDomain.BaseDirectory + fpath;

                rst = Common.FileHandle.WirteCreateFile(Content, filepath + "\\" + info.Title + "." + info.Postfix);
                if (rst == 1)
                {
                    upfInfo.TableName    = "Cm_Templet";
                    upfInfo.RootField    = "";
                    upfInfo.RootId       = "";
                    upfInfo.ParentField  = "";
                    upfInfo.ParentId     = TempletID.ToString();
                    upfInfo.FilePath     = fpath;
                    upfInfo.Remark       = "";
                    upfInfo.FileSize     = 0;
                    upfInfo.FileName     = info.Title;
                    upfInfo.ExpandName   = info.Postfix;
                    upfInfo.UniqueName   = info.Title + "." + info.Postfix;
                    upfInfo.FileTypeId   = tltinfo.ID;
                    upfInfo.AttachmentId = tltinfo.Code;
                    rst = ufDal.UpLoadFile_Add(upfInfo);
                }
            }

            QueryData();

            if (rst == 1)
            {
                MessageBox.Show("保存成功。");
            }
            else
            {
                MessageBox.Show("保存失败。");
            }
        }