1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
| import win.ui; import win.ui.atom; /*DSG{{*/ mainForm = win.form(text="股票交易计算器";right=571;bottom=397;mode="popup") mainForm.add( button={cls="button";text="开始计算";left=449;top=353;right=553;bottom=383;ah=1;aw=1;font=LOGFONT(name='微软雅黑';h=-14);z=3}; button2={cls="button";text="清空重填";left=324;top=353;right=428;bottom=383;ah=1;aw=1;font=LOGFONT(name='微软雅黑';h=-14);z=4}; checkbox={cls="checkbox";text="深市";left=41;top=46;right=94;bottom=66;checked=1;font=LOGFONT(name='微软雅黑';h=-14);z=20}; checkbox1={cls="checkbox";text="沪市";left=95;top=46;right=148;bottom=66;font=LOGFONT(name='微软雅黑';h=-14);z=19}; checkbox2={cls="checkbox";text="融资年息";left=41;top=93;right=115;bottom=113;font=LOGFONT(name='微软雅黑';h=-14);z=21}; checkbox3={cls="checkbox";text="融券年息";left=179;top=93;right=253;bottom=113;font=LOGFONT(name='微软雅黑';h=-14);z=22}; edit={cls="edit";left=202;top=46;right=237;bottom=66;edge=1;font=LOGFONT(name='微软雅黑');z=5}; edit2={cls="edit";left=86;top=138;right=156;bottom=158;edge=1;font=LOGFONT(name='微软雅黑');num=1;z=8}; edit3={cls="edit";left=213;top=138;right=283;bottom=158;edge=1;font=LOGFONT(name='微软雅黑');z=10}; edit4={cls="edit";left=341;top=138;right=411;bottom=158;edge=1;font=LOGFONT(name='微软雅黑');num=1;z=12}; edit5={cls="edit";left=465;top=138;right=535;bottom=158;edge=1;font=LOGFONT(name='微软雅黑');z=13}; edit6={cls="edit";left=254;top=93;right=289;bottom=113;edge=1;font=LOGFONT(name='微软雅黑');z=38}; edit7={cls="edit";left=116;top=93;right=151;bottom=113;edge=1;font=LOGFONT(name='微软雅黑');z=40}; edit8={cls="edit";left=374;top=93;right=409;bottom=113;edge=1;font=LOGFONT(name='微软雅黑');num=1;z=43}; groupbox={cls="groupbox";text="输入信息";left=20;top=17;right=553;bottom=177;ah=1;aw=1;edge=1;font=LOGFONT(name='微软雅黑');z=1}; groupbox2={cls="groupbox";text="计算结果";left=20;top=192;right=553;bottom=335;ah=1;aw=1;edge=1;font=LOGFONT(name='微软雅黑');z=2}; static={cls="static";text="买入佣金=";left=212;top=219;right=286;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=23}; static10={cls="static";text="印花税=";left=40;top=259;right=115;bottom=283;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=17}; static11={cls="static";text="0";left=108;top=259;right=201;bottom=284;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=18}; static12={cls="static";text="卖出佣金=";left=212;top=259;right=286;bottom=282;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=25}; static13={cls="static";text="0";left=278;top=259;right=371;bottom=284;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=26}; static14={cls="static";text="融资利息=";left=384;top=219;right=464;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=27}; static15={cls="static";text="0";left=450;top=219;right=543;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=28}; static16={cls="static";text="融券利息=";left=384;top=259;right=464;bottom=283;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=29}; static17={cls="static";text="0";left=450;top=259;right=543;bottom=284;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=30}; static18={cls="static";text="税费合计=";left=40;top=298;right=115;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=31}; static19={cls="static";text="0";left=108;top=298;right=201;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=32}; static2={cls="static";text="0";left=278;top=219;right=371;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=24}; static20={cls="static";text="盈亏合计=";left=212;top=298;right=286;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=33}; static21={cls="static";text="0";left=278;top=298;right=371;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=34}; static22={cls="static";text="盈亏比例=";left=384;top=298;right=464;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=36}; static23={cls="static";text="0";left=450;top=298;right=543;bottom=323;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=37}; static24={cls="static";text="‰";left=243;top=46;right=267;bottom=66;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=35}; static25={cls="static";text="%";left=291;top=93;right=315;bottom=113;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=39}; static26={cls="static";text="%";left=153;top=93;right=177;bottom=113;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=41}; static27={cls="static";text="计息天数";left=316;top=93;right=384;bottom=113;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=42}; static28={cls="static";text="访问作者博客";left=20;top=355;right=108;bottom=380;ah=1;aw=1;color=16711680;font=LOGFONT(h=-14;name='微软雅黑';underline=1);notify=1;transparent=1;z=44}; static3={cls="static";text="佣金率";left=158;top=46;right=210;bottom=66;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=6}; static4={cls="static";text="买入量";left=41;top=138;right=94;bottom=158;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=7}; static5={cls="static";text="买入价";left=169;top=138;right=222;bottom=158;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=9}; static6={cls="static";text="卖出量";left=296;top=138;right=342;bottom=158;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=11}; static7={cls="static";text="卖出价";left=421;top=138;right=474;bottom=158;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=14}; static8={cls="static";text="过户费=";left=40;top=219;right=115;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=15}; static9={cls="static";text="0";left=108;top=219;right=201;bottom=244;font=LOGFONT(name='微软雅黑';h=-14);transparent=1;z=16} ) /*}}*/
mainForm.static28.oncommand = function(id,event){ process.execute("http://sobaigu.com");
} mainForm.checkbox3.oncommand = function(id,event){ mainForm.checkbox2.checked = false;
}
mainForm.checkbox2.oncommand = function(id,event){ mainForm.checkbox3.checked = false;
}
//沪市被选中时则深市取消选择 mainForm.checkbox1.oncommand = function(id,event){ mainForm.checkbox.checked = false; }
//深市被选中时则沪市取消选择 mainForm.checkbox.oncommand = function(id,event){ mainForm.checkbox1.checked = false; }
//启动时窗口焦点位于买入数量框 mainForm.edit2.setFocus();
mainForm.edit.text = 0.25; mainForm.edit2.text = 0; mainForm.edit3.text = 0; mainForm.edit4.text = 0; mainForm.edit5.text = 0; mainForm.edit6.text = 9.5; mainForm.edit7.text = 8.5; mainForm.edit8.text = 0;
//开始计算按钮 mainForm.button.oncommand = function(id,event){ //取得佣金比例 var chargepercent = mainForm.edit.text; //取得买入价格和买入量 var buyprice = mainForm.edit3.text; var buynum = mainForm.edit2.text; //取得卖出价格和卖出量 var sellprice = mainForm.edit5.text; var sellnum = mainForm.edit4.text; //融资融券年息 var sellyper = mainForm.edit6.text; var buyyper = mainForm.edit7.text; var chargeday = mainForm.edit8.text;
//处理输入不正确 if(buynum == "" or buyprice == "" or sellnum == "" or sellprice == ""){ mainForm.msgbox("请输入正确的数量及价格"); return false; } if((buynum == 0 or buyprice == 0) and (sellnum == 0 or sellprice == 0)){ mainForm.msgbox("请输入正确的数量及价格"); return false; } if((mainForm.checkbox2.checked == true or mainForm.checkbox3.checked == true) and mainForm.edit8.text == ""){ mainForm.msgbox("请输入正确的计息天数"); return false; } //var 过户费 = mainForm.static9.text=((买入股数+卖出股数)/1000)*1,沪市才收; var b = buynum/1000; var s = sellnum/1000; if(b > 0 and b < 1){ b = 1; } if(s > 0 and s < 1){ s = 1; } bs = b + s; if(mainForm.checkbox.checked == true){ bs = 0; } mainForm.static9.text = string.format("%.2f", bs) bs = mainForm.static9.text;
//var 印花税 = mainForm.static11.text=(卖出价格*卖出股数)*1‰; var fcost = (sellprice * sellnum)/1000; mainForm.static11.text = string.format("%.2f", fcost); fcost = mainForm.static11.text;
//var 买入佣金 = mainForm.static2.text=(买入价格*买入股数)*佣金比例,不足5元按5元收; var bcost = buyprice * buynum * chargepercent/1000; if(bcost >0 and bcost <5){ bcost = 5; } mainForm.static2.text = string.format("%.2f", bcost); bcost = mainForm.static2.text;
//var 卖出佣金 = mainForm.static13.text; var scost = sellprice * sellnum * chargepercent/1000; if(scost >0 and scost <5){ scost = 5; } mainForm.static13.text = string.format("%.2f", scost); scost = mainForm.static13.text;
//var 融资利息 = mainForm.static15.text=融资买入额*天数*年息/360; instb = buyprice * buynum * chargeday * buyyper/(100 * 360); if(mainForm.checkbox2.checked != true){ instb = 0; } mainForm.static15.text = string.format("%.2f", instb); instb = mainForm.static15.text;
//var 融券利息 = mainForm.static17.text=融券卖出额*天数*年息/360; insts = sellprice * sellnum * chargeday * sellyper/(100 * 360); if(mainForm.checkbox3.checked != true){ insts = 0; } mainForm.static17.text = string.format("%.2f", insts); insts = mainForm.static17.text;
//var 税费合计 = mainForm.static19.text=买入佣金+[过户费]+卖出佣金+印花税+融资利息|融券利息; mainForm.static19.text = insts + instb + scost + bcost + fcost + bs; vcost = mainForm.static19.text;
//var 盈亏合计 = mainForm.static21.text=卖出金额-买入金额-税费合计+剩余股票市值; vgain = sellprice * sellnum - (buyprice * buynum + vcost); sen = tonumber(sellnum,10); bun = tonumber(buynum,10); if(mainForm.checkbox3.checked != true and sen > bun){ mainForm.msgbox("没这么多股票可卖!"); return false;
} if(sen < bun){ vgain = sellprice * sellnum - buyprice * buynum -vcost + sellprice * (buynum - sellnum); //mainForm.msgbox("sellnum < buynum")
}
mainForm.static21.text = string.format("%.2f", vgain);
//var 盈亏比例 = mainForm.static23.text=盈亏合计/投入金额*100%; pgain = vgain/(buyprice * buynum + vcost); mainForm.static23.text = string.format("%.3f", pgain)*100+"%";
}
mainForm.button2.oncommand = function(id,event){ mainForm.edit3.text = ""; mainForm.edit2.text = ""; mainForm.edit5.text = ""; mainForm.edit4.text = ""; mainForm.edit2.setFocus(); }
var atom,hwnd/*冲突窗口的句柄,该函数会自动激活此窗口*/ = mainForm.atom("stock_calc_by_sobaigu.com"); if(!atom){ /*为窗口设置原子值可以避免一个程序重复运行多个实例*/ win.quitMessage(); return; }
//显示窗体 mainForm.show() win.loopMessage();
|