2018-01-18 Bpmn-JS修改生成的XML、.net(c#) winform文本框输入、AngularJS 事件、伸缩框的设置、DevExpress中GridView上的右键菜单

第一组:刘聪 Bpmn-JS修改生成的XML

1:修改dc:Bound、di:waypoint标签,去掉bpmndi:BPMNLabel(保留其子标签)

ElementSerializer.prototype.serializeTo = function(writer) {
  var hasBody = this.body.length,
      indent = !(this.body.length === 1 && this.body[0] instanceof BodySerializer);
  if ("dc:Bounds,di:waypoint".indexOf(nsName(this.ns)) >= 0) {
      writer
   .appendIndent()
   .append('<omg' + nsName(this.ns));

      this.serializeAttributes(writer);

      //writer.append(hasBody ? '>' : ' />');
      writer.append('>');
      if (hasBody) {

          if (indent) {
              writer
                .appendNewLine()
                .indent();
          }

          forEach(this.body, function (b) {
              b.serializeTo(writer);
          });

          if (indent) {
              writer
                .unindent()
                .appendIndent();
          }
      }
      writer.append('</omg' + nsName(this.ns) + '>');
      writer.appendNewLine();
  }
  else if ("bpmndi:BPMNLabel".indexOf(nsName(this.ns)) >= 0)
  {
      if (hasBody) {
          if (indent) {
              writer
                .appendNewLine()
                .indent();
          }
          forEach(this.body, function (b) {
              b.serializeTo(writer);
          });
          if (indent) {
              writer
                .unindent()
                .appendIndent();
          }      
  }
}
  else {
      writer
        .appendIndent()
        .append('<' + nsName(this.ns));
      this.serializeAttributes(writer);
      //writer.append(hasBody ? '>' : ' />');
      writer.append('>');
      if (hasBody) {
          if (indent) {
              writer
                .appendNewLine()
                .indent();
          }
          forEach(this.body, function (b) {
              b.serializeTo(writer);
          });
          if (indent) {
              writer
                .unindent()
                .appendIndent();
          }
      }
      writer.append('</' + nsName(this.ns) + '>');
      writer.appendNewLine();
  }
};

2.去掉outgoing、incoming标签和内容。

ReferenceSerializer.prototype.serializeTo = function (writer) {
    if ("outgoing,incoming".indexOf(nsName(this.ns)) < 0) {
        writer
          .appendIndent()
          .append('<' + nsName(this.ns) + '>' + this.element.id + '</' + nsName(this.ns) + '>')
          .appendNewLine();
    };
}  

3.去掉BPMN2

function nsName(ns) {
  if (isString(ns)) {
    return ns;
  } else {      
      return ((ns.prefix && "bpmn2".indexOf(ns.prefix)<0)? ns.prefix + ':' : '') + ns.localName;     
  }
}  

4:修改标签里面的属性名称:

ElementSerializer.prototype.serializeAttributes = function(writer) {
 var attrs = this.attrs,
     root = !this.parent;

 if (root) {
   attrs = getNsAttrs(this.namespaces).concat(attrs);
 }
 
 forEach(attrs, function (a) {
     if ("camunda".indexOf(a.name.prefix) >= 0) { a.name.prefix = "activiti"; }
     if ("xmlns:camunda".indexOf(a.name) >= 0) { a.name = "xmlns:activiti" }
     if ("xmlns:dc".indexOf(a.name) >= 0) { a.name = "xmlns:omgdc" }
     if ("xmlns:di".indexOf(a.name) >= 0) { a.name = "xmlns:omgdi" }
     if ("xmlns:bpmn2".indexOf(a.name) >= 0) { a.name = "xmlns" }
     //if ("camunda:candidateGroups".indexOf(a.name) >= 0) { a.name = "activiti:candidateGroups" }
   writer
     .append(' ')  

     .append(nsName(a.name)).append('="').append(a.value).append('"');
 });
};

备注:生成的xml与openDiagram(newDiagramXML)中的newDiagramXML有关。newDiagramXML默认为:

var newDiagramXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bpmn2:definitions xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:bpmn2=\"http://www.omg.org/spec/BPMN/20100524/MODEL\" xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\" xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\" xmlns:camunda=\"http://camunda.org/schema/1.0/bpmn\"  xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\" xsi:schemaLocation=\"http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd\" id=\"sample-diagram\" targetNamespace=\"http://bpmn.io/schema/bpmn\">\n  <bpmn2:process id=\"Process_1\" isExecutable=\"false\">\n    <!-- <bpmn2:startEvent id=\"StartEvent_1\"/>-->\n  </bpmn2:process>\n  <bpmndi:BPMNDiagram id=\"BPMNDiagram_1\">\n    <bpmndi:BPMNPlane id=\"BPMNPlane_1\" bpmnElement=\"Process_1\">\n      <!--<bpmndi:BPMNShape id=\"_BPMNShape_StartEvent_2\" bpmnElement=\"StartEvent_1\">\n        <dc:Bounds height=\"36.0\" width=\"36.0\" x=\"412.0\" y=\"240.0\"/>\n      </bpmndi:BPMNShape>-->\n    </bpmndi:BPMNPlane>\n  </bpmndi:BPMNDiagram>\n</bpmn2:definitions>";

第二组:冯佳丽 .net(c#) winform文本框输入

转载

C#的winform中控制TextBox中只能输入数字(加上固定位数和首位不能为0)
给个最简单的方法:

private void textBox3_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    //阻止从键盘输入键
    e.Handled = true;
    if(e.KeyChar>='0' && e.KeyChar <='9')
    {
        e.Handled = false;
    }

}

或者

private void tbID_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!((e.KeyChar >= '0' && e.KeyChar <= '9') || e.KeyChar == ' '))//不输入输入除了数字之外的所有非法字符的判断
            {
                e.Handled = true;
            }
        }

多条件的:

private void TxtUser_KeyPress(object sender, KeyPressEventArgs e)
        {
            //阻止从键盘输入键
           e.Handled = true;
            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == (char)8))
            {
                if ((e.KeyChar == (char)8)) { e.Handled = false; return; }
                else
                {
                    int len = TxtUser.Text.Length;
                    if (len < 5)
                    {
                        if (len == 0 && e.KeyChar != '0')
                        {
                            e.Handled = false; return;
                        }
                        else if(len == 0)
                        {
                            MessageBox.Show("编号不能以0开头!"); return;
                        }
                        e.Handled = false; return;
                    }
                    else
                    {
                        MessageBox.Show("编号最多只能输入5位数字!");
                    }
                }
            }
            else
            {
                MessageBox.Show("编号只能输入数字!");
            }
           
        }

也可以用正则表达式:

C#Winform下用正则表达式限制TextBox只能输入数字 昨天,在网上特别是园子里搜了下如何在Winform下限制TextBox只能输入数字的功能。可是结果基本上都是在web的环境下用正则表达式实现的,而在Winform的平台下,好像没有发现。 就自己循着思路实现了下。

首先,先定义一个string,用来表示数字的正则表达式:

privatestring pattern =@"^[0-9]*$";

然后再定义一个string,用来记录TextBox原来的内容,以便在输入非数字的时候,文本框的内容可以恢复到原来的值(我不知道TextBox怎么恢复到上一次的内容,只能采用这个笨办法了):

privatestring param1 =null;

接着,我们就可以在textBox的TextChanged事件中判断输入的是否是数字,如果是数字,那么就把文本框的内容保存在param1中;如果不是数字,那么取消这次输入,即重新设置文本框的内容为param1:

        privatevoid textBoxParam1_TextChanged(object sender, EventArgs e)
        {
             Match m = Regex.Match(this.textBoxParam1.Text, pattern);   // 匹配正则表达式

            if (!m.Success)   // 输入的不是数字
            {
                this.textBoxParam1.Text = param1;   // textBox内容不变

                // 将光标定位到文本框的最后
                this.textBoxParam1.SelectionStart =this.textBoxParam1.Text.Length;
             }
            else   // 输入的是数字
            {
                 param1 =this.textBoxParam1.Text;   // 将现在textBox的值保存下来
             }
         }

网页里面:

<asp:textbox id="TextBox1" onkeyup="if(isNaN(value))execCommand('undo')" runat="server"
Width="80px" onafterpaste="if(isNaN(value))execCommand('undo')"></asp:textbox>

其实服务器控件也能加上onkeydown与up等事件的
这样就行了 只能输入小数与数字


第三组:吴景霞 AngularJS 事件

ng-click 指令
ng-click 指令定义了 AngularJS 点击事件。
AngularJS 实例

<div ng-app="" ng-controller="myCtrl">
<button ng-click="count = count + 1">点我!</button>
<p>{{ count }}</p>
</div>

ng-hide 指令用于设置应用部分是否可见。
ng-hide="true" 设置 HTML 元素不可见。
ng-hide="false" 设置 HTML 元素可见。

AngularJS 实例

<div ng-app="myApp" ng-controller="personCtrl">
<button ng-click="toggle()">隐藏/显示</button>
<p ng-hide="myVar">
名: <input type="text" ng-model="firstName"><br>
姓名: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
    $scope.firstName = "John",
    $scope.lastName = "Doe"
    $scope.myVar = false;
    $scope.toggle = function() {
        $scope.myVar = !$scope.myVar;
    };
});
</script> 

应用解析:
第一部分 personController与控制器章节类似。

应用有一个默认属性: $scope.myVar = false;
ng-hide 指令设置 <p>元素及两个输入域是否可见, 根据 myVar 的值 (true 或 false) 来设置是否可见。
toggle() 函数用于切换 myVar 变量的值(true 和 false)。
ng-hide="true" 让元素 不可见。

显示 HTML 元素

ng-show 指令可用于设置应用中的一部分是否可见 。
ng-show="false" 可以设置 HTML 元素 不可见。
ng-show="true" 可以以设置 HTML 元素可见。

以下实例使用了 ng-show 指令:

AngularJS 实例

<div ng-app="myApp" ng-controller="personCtrl">
<button ng-click="toggle()">隐藏/显示</button>
<p ng-show="myVar">
名: <input type="text" ng-model="firstName"><br>
姓: <input type="text" ng-model="lastName"><br>
<br>
姓名: {{firstName + " " + lastName}}
</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
    $scope.firstName = "John",
    $scope.lastName = "Doe"
    $scope.myVar = true;
    $scope.toggle = function() {
        $scope.myVar = !$scope.myVar;
    }
});
</script> 

第四组:傅云 伸缩框的设置

伸缩框的代码

 <script type="text/javascript">
           $(function () {
               $('#iframe2')[0].style.visibility = 'hidden';
               //$('#iframe1')[0].style.visibility = 'hidden';
               //FieldSetVisual('iframe1', 'fset_ShipInportInfo', 'img_ShipInportInfo', 'outdiv');
               FieldSetVisual('iframe2', 'fset_ShipInportInfo2', 'img_ShipInportInfo2');
               $('#iframe1')[0].style.visibility = 'hidden';
               FieldSetVisual('iframe1', 'fset_ShipInportInfo', 'img_ShipInportInfo');
           })
           // 设置FieldSet高度方法,支持IE浏览器、Firefox 
           // 参数1:pTableID,FieldSet内部div或table的id 
           // 参数2:pFieldSetID,FieldSet的ID 
           // 参数3:pImageID,图片的ID,展开或收缩后更新图片SRC 
</script>

第五组:王炳钧 DevExpress中GridView上的右键菜单

网址: https://www.cnblogs.com/kkun/archive/2010/01/14/1647570.html

如上图,先选中GridView,不是GridControl,在属性窗口中,选择事件窗口,注册事件MouseUp

代码如下,其中popupMenu_ResumeGrid为DevExpress.XtraBars.PopupMenu

gridView_ResumeCollection为private DevExpress.XtraGrid.Views.Grid.GridView

private void gridView_ResumeCollection_MouseUp(object sender, MouseEventArgs e) { 
            DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo hi =this.gridView_ResumeCollection.CalcHitInfo(e.Location); 
            if (hi.InRow && e.Button == MouseButtons.Right) { 
                popupMenu_ResumeGrid.ShowPopup(Control.MousePosition); 
            } 
        }

备注序列化和反序列化代码

IFormatter formatter = new BinaryFormatter(); 
                using (Stream stream = new FileStream(ResumeCollection.ToString(), FileMode.Open, FileAccess.Read, FileShare.Read)) { 
                    if (stream.Length > 0) { 
                        formatter.Serialize(stream, new object()); 
                        //ResumeCollection = (ResumeCollection)formatter.Deserialize(stream); 
                        stream.Close(); 
                    } 
                }
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,165评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,503评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,295评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,589评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,439评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,342评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,749评论 3 387
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,397评论 0 255
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,700评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,740评论 2 313
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,523评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,364评论 3 314
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,755评论 3 300
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,024评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,297评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,721评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,918评论 2 336

推荐阅读更多精彩内容