版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、C#代碼優(yōu)化旳案例代碼簡潔代碼簡潔,減少代碼量,初始值盡量在屬性上設立,而不是編寫代碼。合同記錄分析中JToolComBox_ColmunType_SelectedIndexChanged措施中:switch (jToolComBox_ColmunType.SelectedIndex.ToString() case 0:/執(zhí)行金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e22; jWebChart1.SetUrl(); break; case 1:/變更金額 jWebChart1.chartId = 9cc897e5-99d
2、d-468d-84db-3390a18f0e23; jWebChart1.SetUrl(); break; case 2:/索賠金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e24; jWebChart1.SetUrl(); break; case 3:/付款批復金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e25; jWebChart1.SetUrl(); break; case 4:/實際支付金額 jWebChart1.chartId = 9cc897e5
3、-99dd-468d-84db-3390a18f0e26; jWebChart1.SetUrl(); break; case 5:/合同份數 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e27; jWebChart1.SetUrl(); break; default:/執(zhí)行金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e22; jWebChart1.SetUrl(); break; 重構后:switch (jToolComBox_ColmunType.Select
4、edIndex.ToString() case 0:/執(zhí)行金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e22; break; case 1:/變更金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e23; break; case 2:/索賠金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e24; break; case 3:/付款批復金額 jWebChart1.chartId = 9cc897e5
5、-99dd-468d-84db-3390a18f0e25; break; case 4:/實際支付金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e26; break; case 5:/合同份數 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e27; break; default:/執(zhí)行金額 jWebChart1.chartId = 9cc897e5-99dd-468d-84db-3390a18f0e22; break; jWebChart1.SetUrl();合同綜
6、合查詢中jTabControl8_SelectedIndexChanged措施中多種If語句(3個以上),改寫為switch合同綜合查詢中JeMisQuery_V_HT_CONTRACT_SHOW_TJ_OnQueryFinished措施中/請?zhí)顚懩_本 decimal de_SIGN_AMOUNT = 0; decimal de_ALTER_AMOUNT = 0; decimal de_ALL_CLAIM_AMOUNT = 0; decimal de_PAY_AMOUNT = 0; decimal de_ALL_RP_AMOUNT = 0; decimal de_EXE_AMOUNT = 0;
7、 decimal de_APPLY_AMOUNT = 0; decimal de_APPLY_APPROVE_AMOUNT = 0; string str_where = eMisQuery_V_HT_CONTRACT_SHOW.UserCustomCondition; string sql = select count(*) as ht_contract_count,sum(SIGN_AMOUNT)nvl(sum(SIGN_AMOUNT), 0) as SIGN_AMOUNT,sum(ALTER_AMOUNT) as ALTER_AMOUNT, + sum(ALL_CLAIM_AMOUNT)
8、as ALL_CLAIM_AMOUNT,sum(PAY_AMOUNT) as PAY_AMOUNT, sum(ALL_RP_AMOUNT) as ALL_RP_AMOUNT, sum(EXE_AMOUNT) as EXE_AMOUNT + ,sum(APPLY_AMOUNT) as APPLY_AMOUNT, sum(APPLY_APPROVE_AMOUNT) as APPLY_APPROVE_AMOUNT from GCMIS.v_ht_contact_show t where + str_where; DataSet ds = eMisSurface1.ExecQuerySql(sql);
9、 if (ds != null & ds.Tables.Count 0) /故意義不,肯定為True DataRow dr = ds.Tables0.Rows0; jLabel_Jl.Text = drht_contract_count.ToString(); object obj = drSIGN_AMOUNT; de_SIGN_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); /為什么要jLabel_QD.Text = drSIGN_AMOUNT.ToString(0.00); 先轉成Decimal,再轉成String jLab
10、el_QD.Text = de_SIGN_AMOUNT.ToString(0.00); obj = drALTER_AMOUNT; de_ALTER_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_BG.Text = de_ALTER_AMOUNT.ToString(0.00); obj = drALL_CLAIM_AMOUNT; de_ALL_CLAIM_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_SP.Text = de_ALL_C
11、LAIM_AMOUNT.ToString(0.00); obj = drPAY_AMOUNT; de_PAY_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_ZF.Text = de_PAY_AMOUNT.ToString(0.00); obj = drALL_RP_AMOUNT; de_ALL_RP_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_JF.Text = de_ALL_RP_AMOUNT.ToString(0.00); obj
12、 = drEXE_AMOUNT; de_EXE_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_ZX.Text = de_EXE_AMOUNT.ToString(0.00); obj = drAPPLY_AMOUNT; de_APPLY_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_SQ.Text = de_APPLY_AMOUNT.ToString(0.00); obj = drAPPLY_APPROVE_AMOUNT; de_APPL
13、Y_APPROVE_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); jLabel_PF.Text = de_APPLY_APPROVE_AMOUNT.ToString(0.00); Else /永遠不會執(zhí)行 jLabel_Jl.Text = 0; jLabel_QD.Text = 0.00; jLabel_BG.Text = 0.00; jLabel_SP.Text = 0.00; jLabel_ZF.Text = 0.00; 應當直接在屬性中設立初始值 jLabel_JF.Text = 0.00; jLabel_ZX.Text
14、= 0.00; jLabel_SQ.Text = 0.00; jLabel_PF.Text = 0.00; return; 提高代碼旳執(zhí)行效率盡量減少不必要旳計算、循環(huán)等,提高代碼旳效率合同記錄分析GET_CONTRACT_COLLECT_SOURCE措施decimal de_SIGN_AMOUNT = 0; decimal de_ALTER_AMOUNT = 0; decimal de_ALL_CLAIM_AMOUNT = 0; decimal de_PAY_AMOUNT = 0; decimal de_ALL_RP_AMOUNT = 0; decimal de_EXE_AMOUNT = 0
15、; decimal de_APPLY_AMOUNT = 0; decimal de_APPLY_APPROVE_AMOUNT = 0; decimal de_FINAL_AMOUNT = 0; int conatratCount = dt.Rows.Count; if (conatratCount = 0) this.jLabel_Contrat_Count.Text = 0; jLabel_SIGN_AMOUNT.Text = 0.00; jLabel_ALTER_AMOUNT.Text = 0.00; jLabel_CLAIM_AMOUNT.Text = 0.00; jLabel_PAY_
16、AMOUNT.Text = 0.00; jLabel_RP_AMOUNT.Text = 0.00; jLabel_EXE_AMOUNT.Text = 0.00; jLabel_APPLY_AMOUNT.Text = 0.00; jLabel_APPROVE_AMOUNT.Text = 0.00; return; DataTable cloneTable = dt.Clone(); foreach (DataRow item in dt.Rows) string code = itemZONE_CODE.ToString(); string codeLength = code.Split(_);
17、 if (codeLength.Length = 3) DataRow copyRow = cloneTable.NewRow(); copyRow.ItemArray = item.ItemArray.Clone() as object; cloneTable.Rows.Add(copyRow); object obj = cloneTable.Compute(sum(CONTACT_COUNT), true); string count = Convert.ToString(obj is DBNull ? 0 : obj); this.jLabel_Contrat_Count.Text =
18、 count; obj = cloneTable.Compute(sum(SIGN_AMOUNT), true); de_SIGN_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_SIGN_AMOUNT.Text = de_SIGN_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(ALTER_AMOUNT), true); de_ALTER_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj);
19、this.jLabel_ALTER_AMOUNT.Text = de_ALTER_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(ALL_CLAIM_AMOUNT), true); de_ALL_CLAIM_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_CLAIM_AMOUNT.Text = de_ALL_CLAIM_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(PAY_AMOUNT), tr
20、ue); de_PAY_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_PAY_AMOUNT.Text = de_PAY_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(ALL_RP_AMOUNT), true); de_ALL_RP_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_RP_AMOUNT.Text = de_ALL_RP_AMOUNT.ToString
21、(0.00); obj = cloneTable.Compute(sum(EXE_AMOUNT), true); de_EXE_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_EXE_AMOUNT.Text = de_EXE_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(APPLY_AMOUNT), true); de_APPLY_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this
22、.jLabel_APPLY_AMOUNT.Text = de_APPLY_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(APPLY_APPROVE_AMOUNT ), true); de_APPLY_APPROVE_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_APPROVE_AMOUNT.Text = de_APPLY_APPROVE_AMOUNT.ToString(0.00); obj = cloneTable.Compute(sum(FINA
23、L_AMOUNT ), true); de_FINAL_AMOUNT = Convert.ToDecimal(obj is DBNull ? 0.00 : obj); this.jLabel_FINAL_AMOUNT.Text = de_FINAL_AMOUNT.ToString(0.00);重構后:DataRow hz_Row = dt.Select(ZONE_CODE=DT); if (hz_Row.Length = 0) return; DataRow cur_hzRow = hz_Row0; this.jLabel_Contrat_Count.Text = cur_hzRowCONTA
24、CT_COUNT.ToString(); this.jLabel_SIGN_AMOUNT.Text = cur_hzRowSIGN_AMOUNT.ToString(); this.jLabel_ALTER_AMOUNT.Text = cur_hzRowALTER_AMOUNT.ToString(); this.jLabel_CLAIM_AMOUNT.Text = cur_hzRowALL_CLAIM_AMOUNT.ToString(); this.jLabel_PAY_AMOUNT.Text = cur_hzRowPAY_AMOUNT.ToString(); this.jLabel_RP_AM
25、OUNT.Text = cur_hzRowALL_RP_AMOUNT.ToString(); this.jLabel_EXE_AMOUNT.Text = cur_hzRowEXE_AMOUNT.ToString(); this.jLabel_APPLY_AMOUNT.Text = cur_hzRowAPPLY_AMOUNT.ToString(); this.jLabel_APPROVE_AMOUNT.Text = cur_hzRowAPPLY_APPROVE_AMOUNT.ToString(); this.jLabel_FINAL_AMOUNT.Text = cur_hzRowFINAL_AMOUNT.ToString();合同記錄分析JBtn_Query_Click措施if (jCHK_ALL.Checked != true) if (jCHK_FENG.Checked) sb.Append( G.PROJECT_TYPE IN(1); if (jCHK_HUO.Checked) if (sb.Length = 0) sb.Append( G.PROJECT_TYPE IN(0); else sb.Append(,0); if (jCHK_SHUI.Checked) if (sb.Length = 0) sb.Ap
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年度網絡安全服務協(xié)議書
- 2024年度版權使用與授權合同
- 2024供水、供電合同范文
- 2024年建筑工程股權轉讓合同樣本
- 2024城市軌道交通安檢設備采購合同
- 文書模板-產品委外開發(fā)合作協(xié)議書
- 產業(yè)新城課件教學課件
- 2024年度企業(yè)品牌形象設計及VI手冊整編合同
- 2024年度版權購買與授權合同具體內容
- 2024年廢物回收居間買賣合同
- 滅火器的規(guī)格與使用培訓
- 2024《中央企業(yè)安全生產治本攻堅三年行動方案(2024-2026年)》
- 紀錄片《園林》解說詞
- 建筑專題攝影培訓課件
- 《民間文學導論》課件
- 《輸血查對制度》課件
- 拳擊賽策劃方案
- 分離性障礙教學演示課件
- 年會拜年祝福視頻腳本
- 文松宋曉峰小品《非誠不找》奇葩男女來相親金句不斷臺詞劇本完整版
- 物理化學第二章 熱力學第二定律
評論
0/150
提交評論