前戏:针对上一篇列出来的功能点,今天和大家分享下这个自定义的公式是怎么设计的,由于我的第一篇博客在首页被管理员移走了,大家可以点击这里来跳转,看下第一篇的目录结构。本人作为老菜鸟,和大家分享的也是一些老菜鸟的想法,大神千万别喷我.

设计背景:当初为什么要设计这个自定义的计算公式呢,原因就是,这个价格是不确定的,计算方式也是不确定的,那如果在代码里面写死,那将来修改起来会比较麻烦,作为老菜鸟,我想偷懒了,也是为了省事。

如何设计:这对目前项目的情况,计算的过程应该是按照线性的方式来计算的,那么问题就简单了。

首先我们先要定义一个范围控件,这个控件的目的就是,在某个区间之内,设置固定的金额或者单价,

一下我列出了部分代码,供大家提供思路

  1 public partial class RolesUserControl :  UserControl
  2
  3     {
  4
  5         public delegate void DelLast(object o, DeleteEventArgs e);
  6
  7
  8
  9         public event DelLast onLeftTextBox;
 10
 11
 12
 13         public delegate void DeleteControl(object o, DeleteEventArgs e);
 14
 15         public event DeleteControl onDelete;
 16
 17
 18
 19         /// <summary>
 20
 21         /// 控件索引
 22
 23         /// </summary>
 24
 25         public int Index { get; set; }
 26
 27
 28
 29         /// <summary>
 30
 31         /// 是否验证成功
 32
 33         /// </summary>
 34
 35         public bool isRegistOK { get; set; }
 36
 37
 38
 39         /// <summary>
 40
 41         /// 是否启用关闭
 42
 43         /// </summary>
 44
 45         public bool ShowClose
 46
 47         {
 48
 49             set
 50
 51             {
 52
 53                 this.pictureBox1.Enabled = value;
 54
 55             }
 56
 57         }
 58
 59
 60
 61         /// <summary>
 62
 63         /// 是否显示关闭
 64
 65         /// </summary>
 66
 67         public bool ShowCloseVisible
 68
 69         {
 70
 71             set
 72
 73             {
 74
 75                 this.pictureBox1.Visible = value;
 76
 77             }
 78
 79         }
 80
 81
 82
 83         private int _dropDownListType = 2;
 84
 85
 86
 87         /// <summary>
 88
 89         /// 交易类型
 90
 91         /// 1:金额
 92
 93         /// 2:单价
 94
 95         /// </summary>
 96
 97         public int DropDownListType { get { return this._dropDownListType; } }
 98
 99
100
101         public RolesUserControl()
102
103         {
104
105             InitializeComponent();
106
107         }
108
109
110
111         /// <summary>
112
113         /// 构造
114
115         /// </summary>
116
117         /// <param name="strLast"></param>
118
119         public RolesUserControl(string strLast)
120
121         {
122
123             InitializeComponent();
124
125             this.tb_last1.Text = strLast;
126
127         }
128
129
130
131         /// <summary>
132
133         /// 鼠标移开TextBox
134
135         /// </summary>
136
137         /// <param name="sender"></param>
138
139         /// <param name="e"></param>
140
141         private void tb_last2_Leave(object sender, EventArgs e)
142
143         {
144
145             decimal d = 0.00m;
146
147             if (!decimal.TryParse(this.tb_last2.Text, out d))
148
149             {
150
151                 isRegistOK = false;
152
153                 this.tb_last2.Text = "请在这里输入格式为24.5的数据";
154
155                 return;
156
157             }
158
159
160
161             if (decimal.Parse(this.tb_last1.Text.Trim()) >= d)
162
163             {
164
165                 isRegistOK = false;
166
167                 this.tb_last2.Text = "下限数据应该大于上限数据";
168
169                 return;
170
171             }
172
173
174
175             if (onLeftTextBox != null)
176
177             {
178
179                 DeleteEventArgs dea = new DeleteEventArgs();
180
181                 dea.ControlName = this.Name;
182
183                 dea.Index = this.Index;
184
185                 dea.StrText = this.tb_last2.Text.Trim();
186
187                 this.onLeftTextBox(sender, dea);
188
189             }
190
191             this.isRegistOK = true;
192
193
194
195         }
196
197
198
199         /// <summary>
200
201         /// 点击关闭
202
203         /// </summary>
204
205         /// <param name="sender"></param>
206
207         /// <param name="e"></param>
208
209         private void pictureBox1_Click(object sender, EventArgs e)
210
211         {
212
213             if (this.onDelete != null)
214
215             {
216
217                 DeleteEventArgs e1 = new DeleteEventArgs();
218
219                 e1.ControlName = this.Name;
220
221                 e1.Index = this.Index;
222
223                 onDelete(sender, e1);
224
225             }
226
227         }
228
229
230
231         /// <summary>
232
233         /// 切换类型,是使用单价还是使用金额
234
235         /// </summary>
236
237         /// <param name="sender"></param>
238
239         /// <param name="e"></param>
240
241         private void ddl_type_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
242
243         {
244
245             if (this.ddl_type.Text == "金额")
246
247             {
248
249                 radLabel1.Text = "吨   金额:";
250
251                 tb_amount.Visible = true;
252
253                 tb_amount.Text = "";
254
255                 this._dropDownListType = 1;
256
257             }
258
259             else
260
261             {
262
263                 radLabel1.Text = "吨   单价:";
264
265                 tb_amount.Visible = false;
266
267                 tb_amount.Text = "";
268
269                 this._dropDownListType = 2;
270
271             }
272
273         }
274
275
276
277         /// <summary>
278
279         /// 判断是否满足条件
280
281         /// </summary>
282
283         /// <param name="sender"></param>
284
285         /// <param name="e"></param>
286
287         private void tb_amount_Leave(object sender, EventArgs e)
288
289         {
290
291             decimal d = 0.00m;
292
293             if (!decimal.TryParse(this.tb_amount.Text, out d))
294
295             {
296
297                 isRegistOK = false;
298
299                 this.tb_amount.Text = "请在这里输入格式为24.5的数据";
300
301                 return;
302
303             }
304
305
306
307             if (onLeftTextBox != null)
308
309             {
310
311                 DeleteEventArgs dea = new DeleteEventArgs();
312
313                 dea.ControlName = this.Name;
314
315                 dea.Index = this.Index;
316
317                 dea.StrText = this.tb_last2.Text.Trim();
318
319                 this.onLeftTextBox(sender, dea);
320
321             }
322
323             this.isRegistOK = true;
324
325         }
326
327
328
329         private void tb_amount_KeyPress(object sender, KeyPressEventArgs e)
330
331         {
332
333             if ((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 190 || e.KeyChar == 110 || e.KeyChar == 13 || e.KeyChar == 8 || e.KeyChar == 46)
334
335             { }
336
337             else
338
339             {
340
341                 tb_amount.Text = "";
342
343                 MessageBox.Show("请输入数字");
344
345                 return;
346
347             }
348
349         }
350
351 }

那么对于上限,其实他也是个线性的,那么我们也来建立一个控件

这个控件用来计算最后临界值。

下面是重点代码,供大家解读

  1 /// <summary>
  2
  3         /// 添加保存事件
  4
  5         /// </summary>
  6
  7         /// <param name="sender"></param>
  8
  9         /// <param name="e"></param>
 10
 11         private void radButton2_Click(object sender, EventArgs e)
 12
 13         {
 14
 15             if (this.tb_RoleName.Text.Trim() == "")
 16
 17             {
 18
 19                 this.MessageBoxShow("请输入角色名称");
 20
 21                 return;
 22
 23             }
 24
 25
 26
 27             //解析界面数据
 28
 29             Model.AutoWater_Sys_BaseRoles br = new Model.AutoWater_Sys_BaseRoles();
 30
 31             br.RolesName = this.tb_RoleName.Text.Trim();
 32
 33             br.CreateBy = this.CurrentUserName;
 34
 35             br.CreateOn = DateTime.Now;
 36
 37             br.IsUsing = true;
 38
 39             br.IsDefault = false;
 40
 41             br.RowState = 1;
 42
 43             br.ID = Guid.NewGuid();
 44
 45
 46
 47             List<Model.AutoWater_Sys_BaseRolesDetail> lbrd = new List<Model.AutoWater_Sys_BaseRolesDetail>();
 48
 49
 50
 51             List<RolesUserControl> _List = new List<RolesUserControl>();
 52
 53             //开始范围
 54
 55             //rolesUserControl1 ,校验数据是否正确
 56
 57             _List.Add(this.rolesUserControl1);
 58
 59             string strMsg="";
 60
 61             bool isVaild = this.VaildRolesUserControl(this.rolesUserControl1, ref strMsg);
 62
 63             if (!isVaild)
 64
 65             {
 66
 67                 _List.Clear();
 68
 69                 MessageBoxShow(strMsg);
 70
 71                 return;
 72
 73             }
 74
 75             //遍历Panel
 76
 77             foreach (Control c in this.radPanel1.Controls)
 78
 79             {
 80
 81                 isVaild = this.VaildRolesUserControl(c as RolesUserControl, ref strMsg);
 82
 83                 if (!isVaild)
 84
 85                 {
 86
 87                     _List.Clear();
 88
 89                     MessageBoxShow(strMsg);
 90
 91                     return;
 92
 93                 }
 94
 95                 _List.Add(c as RolesUserControl);
 96
 97             }
 98
 99             string strValue1,strValue2,strValue3,strValues4;
100
101             _List.ForEach(t => {
102
103                 //Last1
104
105                 strValue1 = (t.Controls.Find("tb_last1", true)[0] as RadTextBox).Text;
106
107                 //Last2
108
109                 strValue2 = (t.Controls.Find("tb_last2", true)[0] as RadTextBox).Text;
110
111                 //Price
112
113                 if (t.DropDownListType == 1)
114
115                 {
116
117                     strValue3 = (t.Controls.Find("tb_amount", true)[0] as RadTextBox).Text;
118
119                 }
120
121                 else
122
123                 {
124
125                     strValue3 = (t.Controls.Find("ddl_price", true)[0] as RadDropDownList).Text;
126
127                 }
128
129
130
131                 lbrd.Add(new Model.AutoWater_Sys_BaseRolesDetail() {
132
133                  BaseTablesID=br.ID,
134
135                   ID=Guid.NewGuid(),
136
137                    BetweenValue=decimal.Parse(strValue2)-decimal.Parse(strValue1),
138
139                     CountType=t.DropDownListType,
140
141                      CountTypeValue=decimal.Parse(strValue3),
142
143                       CreateBy=this.CurrentUserName,
144
145                        CreateOn=DateTime.Now,
146
147                         DownValue=decimal.Parse(strValue1),//下限不低于
148
149                          UpValue = decimal.Parse(strValue2),//上限不超过
150
151                           SortID=t.Index,
152
153                 });
154
155             });
156
157
158
159             //检查范围N
160
161             //单价
162
163             strValues4 = (this.userLastRolesControl1.Controls.Find("ddl_price", true)[0] as RadDropDownList).Text;
164
165             //吨数范围
166
167             strValue3= (this.userLastRolesControl1.Controls.Find("tb_last2", true)[0] as RadTextBox).Text;
168
169             if (strValues4 != "" && strValue3!="")
170
171             {
172
173                 lbrd.Add(new Model.AutoWater_Sys_BaseRolesDetail() {
174
175                  BaseTablesID=br.ID,
176
177                   SortID=9,
178
179                    BetweenValue=decimal.Parse(strValue3),
180
181                     UpValue=0.00m,
182
183                       DownValue = decimal.Parse(strValue3),
184
185                       CreateOn=DateTime.Now,
186
187                        CreateBy=this.CurrentUserName,
188
189                         ID=Guid.NewGuid(),
190
191                          CountTypeValue=decimal.Parse(strValues4),
192
193                           CountType=3,
194
195                 });
196
197             }
198
199
200
201             Combin<Model.AutoWater_Sys_BaseRoles, List<Model.AutoWater_Sys_BaseRolesDetail>> combinList = new Combin<Model.AutoWater_Sys_BaseRoles, List<Model.AutoWater_Sys_BaseRolesDetail>>(br,lbrd);
202
203             bool isAddOK=SettingHelper.Init.AddBaseRoles(combinList);
204
205             if (isAddOK)
206
207             {
208
209                 this.MessageBoxShow("建立规则成功!");
210
211                 combinList = null;
212
213                 lbrd.Clear();
214
215                 br = null;
216
217                 lbrd = null;
218
219                 this.Close();
220
221             }
222
223             else
224
225             {
226
227                 this.MessageBoxShow("建立规则失败!");
228
229             }
230
231         }

到此以上就是设置了定义计算规则的逻辑,是不是很简单,有了这些数据的规则之后,接下来就是解析这些数据了,有兴趣的朋友可以自己设计下,然后自己解析,因为这些在老菜鸟看来这些都是儿科的玩意,好了今天就和大家分享到这里,明天给大家分享下,我这个老菜鸟是如何开发发票设计器的,如何来动态设计发票模板,各位88

转载于:https://www.cnblogs.com/fourspace/p/5822918.html

一个6年的菜鸟,在4年之前做的一些功能(二)相关推荐

  1. 手把手教你如何搭建一个自己的安卓快速开发框架之带你做自己的APP(二)

    ####点击查看上一篇文章:手把手教你如何搭建一个自己的安卓快速开发框架之BaseActivity(一) 继上一篇我实现了基本的BaseActivity,包含 ToolBar 透明状态栏 生命周期监控 ...

  2. python发音机器人_只需三步,菜鸟也能用Python做一个简易版Siri

    原标题:只需三步,菜鸟也能用Python做一个简易版Siri 当下,各个手机厂商都陆续的推出了属于自己的智能手机机器人,像是苹果的Siri,小米的小爱,还有等等.这些智能机器人不仅仅方便了我们对于手机 ...

  3. 终于入门:一个渣渣专科的菜鸟,学习编程近一年的感悟

    这是一个渣渣专科的菜鸟,学习编程近一年的感悟. 终于找到了一份我满意它,它也满意我的工作了,近一年的学习,我终于快入门了.想写下自己这一路来的心路历程与感受,希望可以给后来者一些心灵上的激励. 之前准 ...

  4. 请听一个故事------gt;百度员工离职总结:如何做个好员工

    (本文转载于互联网:http://mp.weixin.qq.com/s?__biz=MzA3MDMyODYyOA==&mid=200222421&idx=1&sn=ee0890 ...

  5. 手机上图片信息怎么拉一个矩形框_华为手机EMUI系统隐藏的10个功能,上手体验后,实用性无敌了...

    阅读本文前,请您先点击上面的"蓝色字体",再点击"关注",这样您就可以继续免费收到文章了.每天都有分享,完全是免费订阅,请放心关注. 注:本文转载自网络,如有侵 ...

  6. 数据结构 图定义和实现 根据郑州轻工业大学的校园平面图设计一个简单的校园导航系统,设计数据结构和算法实现相应功能

    题目:根据郑州轻工业大学科学校区的校园平面图设计一个简单的校园导航系统,设计数据结构和算法实现相应功能.要求所含景点不少于8个(软件学院为其中一个景点).以图中顶点表示学校内各景点,存放景点的名称.景 ...

  7. 一个完整的短视频包含哪些要素?做短视频还要学会把控全局

    一个完整的短视频包含哪些要素?做短视频还要学会把控全局 对于做短视频的小伙伴们来说,首先一定要了解做短视频的具体流程,有了理论知识后再上手实操,才能事半功倍.那么我们今天就一起来学习一下一个完整的短视 ...

  8. 小程序制作预算_做一个小程序的大概预算是多少?做一个小程序大概多少钱?...

    做一个小程序的大概预算是多少?做一个小程序大概多少钱?下面跟随小编一起来看看吧! 小程序开发需要多少钱,这个要看你做什么样的小程序, 你对小程序的功能.框架.定位.交互.UI的要求是什么? 这些都需要 ...

  9. 自己做点小生意一个月能够挣1-2万,在公司上班一个月薪2万,要是你回选择做生意还是在单位上班?...

    自己做点小生意一个月能够挣1-2万,在公司上班一个月薪2万,要是你会选择做生意还是在单位上班? 说说我自己的选择,要是我的话,我会选择自己做生意,虽然收入比上班,但有两个原因我更倾向自己做生意. 1. ...

最新文章

  1. 分享一下SecureCRT输出颜色和格式
  2. 机器学习理论与实战(十四)概率图模型02
  3. 非递归遍历求二叉排序树的深度
  4. hdfs web_ui深入讲解、服务启动日志分析、NN SNN关系
  5. 普元部署包部署找不到构建_让我们在5分钟内构建和部署AutoML解决方案
  6. 【论文党福利】如何提取图像中的数据
  7. python使用HDF文件格式,保存多个类型的数据到一个文件
  8. 一步设置Intellij IDEA 热部署处理方法
  9. [C++]二维数组还是一维数组?
  10. WPF与输入法冲突研究之三:韩文输入法在不同平台,WinForm/WPF下的区别
  11. Android 人脸识别,活体检测离线SDK
  12. 医学图像预处理之CT成像原理
  13. 安卓android usb 转 RS 232 串口 芯片的比较
  14. The nodejs-legacy package simply installs a symbolic link so that it can be executed using the node
  15. selenium操作360极速浏览器的方法
  16. 学计算机专业的买游戏本能用吗,2020好用的游戏本有哪些_2020适合高考后购买的游戏本...
  17. 调用阿里云短信服务接口实现短信验证码
  18. 助力创业者成就未来,亚马逊云科技优势何在?
  19. [题集]ADS13 Randomized Algorithms
  20. linux下查看二进制文件的命令

热门文章

  1. mysql恢复数据的步骤_MySQL备份恢复数据的一般步骤
  2. php引用php,PHP7引入的??和?:的区别讲解
  3. vs安装一直在提取文件_Visual Studio 2019下载及安装教程
  4. steamvr unity 连接眼镜_150度FOV,自研显示方案,Kura公布全新AR眼镜Gallium
  5. python 面向对象(云储存一下)
  6. 现在的编译器还需要手动展开循环吗_性能 - 如果有的话,循环展开仍然有用吗?...
  7. PCL调错(2):VTK报错
  8. 1数字图像获取:1.2图像灰度直方图
  9. 机器学习中的数学基础(4.1):支持向量机Support Vector Machine(SVM)
  10. 力扣(LeetCode)刷题,简单题(第18期)