protected string GetSaItemName(string saItemId) { SASalaryItemService sASalaryItemService = new SASalaryItemService(); SASalaryItem byId = sASalaryItemService.GetById(saItemId); return(byId.Name); }
protected void btnSaveData_Click(object sender, System.EventArgs e) { try { string name = this.txtSalaryName.Text.Trim(); string note = this.txtNote.Text.Trim(); if (string.IsNullOrEmpty(name)) { base.RegisterShow("系统提示", "名称不能为空,保存失败!"); this.BindGV(); } else { int num = ( from si in this.ItemService where si.Name == name select si).Count <SASalaryItem>(); if (this.hfldType.Value.Trim() == "add") { if (num > 0) { base.RegisterShow("系统提示", "名称已经存在,保存失败!"); return; } SASalaryItem sASalaryItem = new SASalaryItem(); int num2 = this.ItemService.Max((SASalaryItem si) => si.No); sASalaryItem.Id = System.Guid.NewGuid().ToString(); sASalaryItem.No = num2 + 1; sASalaryItem.Name = name; sASalaryItem.IsAllowDel = true; sASalaryItem.Note = note; this.ItemService.Add(sASalaryItem); } else { SASalaryItem byId = this.ItemService.GetById(this.hfldCheckedId.Value.Trim()); if (byId.Name != name && num > 0) { base.RegisterShow("系统提示", "名称已经存在,保存失败!"); return; } byId.Name = name; byId.Note = note; this.ItemService.Update(byId); } this.BindGV(); base.RegisterShow("系统提示", "保存成功!"); } } catch { base.RegisterShow("系统提示", "保存失败!"); } }
private decimal GetTaxrateDeduct(string saItemCode, int level) { SASalaryItem saItem = ( from sis in this.saItemService where sis.Code == "Taxable" select sis).FirstOrDefault <SASalaryItem>(); SASalaryBooksItem sASalaryBooksItem = ( from sbi in this.saBooksItemService where sbi.BooksId == this.ddlSaBooks.SelectedValue && sbi.ItemId == saItem.Id select sbi).FirstOrDefault <SASalaryBooksItem>(); decimal taxrateDeduct; if (sASalaryBooksItem != null) { if (sASalaryBooksItem.IsFormula) { if (!string.IsNullOrEmpty(sASalaryBooksItem.Formula)) { string expression = this.RepalceFormula(sASalaryBooksItem.Formula, --level); decimal value = 0m; try { value = CalculatorHelper.Calc(expression); } catch (System.Exception ex) { if (ex.Message == "计算错误") { value = 0m; } } taxrateDeduct = this.GetTaxrateDeduct(value, saItemCode); } else { taxrateDeduct = this.GetTaxrateDeduct(0m, saItemCode); } } else { decimal value2 = (!sASalaryBooksItem.DefaultValue.HasValue) ? 0m : sASalaryBooksItem.DefaultValue.Value; taxrateDeduct = this.GetTaxrateDeduct(value2, saItemCode); } } else { taxrateDeduct = this.GetTaxrateDeduct(0m, saItemCode); } return(taxrateDeduct); }
protected string ConvertFormula(string formula) { string[] array = formula.Split(new char[] { '[' }); System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text = array2[i]; if (text.Contains(']')) { string item = text.Substring(0, text.IndexOf(']')); if (!list.Contains(item)) { list.Add(item); } } } System.Collections.Generic.List <SaBooksItem> list2 = new System.Collections.Generic.List <SaBooksItem>(); SASalaryItemService sASalaryItemService = new SASalaryItemService(); foreach (string booksItemId in list) { SASalaryBooksItem sASalaryBooksItem = ( from sbi in this.saBooksItemService where sbi.Id == booksItemId select sbi).FirstOrDefault <SASalaryBooksItem>(); if (sASalaryBooksItem != null) { SASalaryItem byId = sASalaryItemService.GetById(sASalaryBooksItem.ItemId); SaBooksItem saBooksItem = new SaBooksItem(); if (byId != null) { saBooksItem.Id = "[" + booksItemId + "]"; saBooksItem.ItemName = "[" + byId.Name + "]"; list2.Add(saBooksItem); } } } foreach (SaBooksItem current in list2) { formula = formula.Replace(current.Id, current.ItemName); } return(formula); }
protected void btnDelete_Click(object sender, System.EventArgs e) { System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); if (this.hfldCheckedId.Value.Contains('[')) { list = JsonHelper.GetListFromJson(this.hfldCheckedId.Value); } else { list.Add(this.hfldCheckedId.Value); } try { System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(); SASalaryBooksItemService source = new SASalaryBooksItemService(); SAMonthSalaryService source2 = new SAMonthSalaryService(); foreach (string id in list) { SASalaryItem byId = this.ItemService.GetById(id); int num = ( from sbi in source where sbi.ItemId == id select sbi).Count <SASalaryBooksItem>(); int num2 = ( from sms in source2 where sms.ItemId == id select sms).Count <SAMonthSalary>(); if (num == 0 && num2 == 0) { this.ItemService.Delete(byId); } else { stringBuilder.Append("名称为" + byId.Name + "的工资项在"); if (num > 0) { stringBuilder.Append("帐套"); } if (num > 0 && num2 > 0) { stringBuilder.Append("和"); } if (num2 > 0) { stringBuilder.Append("工资表"); } stringBuilder.Append("中正在使用,不能执行删除!"); } } if (!string.IsNullOrEmpty(stringBuilder.ToString())) { base.RegisterShow("系统提示", stringBuilder.ToString()); } else { base.RegisterShow("系统提示", "删除成功!"); } this.BindGV(); } catch { base.RegisterShow("系统提示", "删除失败!"); } }
private string RepalceFormula(string formula, int level) { if (level < 0) { throw new System.Exception("生成失败,请确认公式逻辑是否正确或者计算额度是否过大!"); } if (!string.IsNullOrEmpty(formula)) { string[] array = formula.Split(new char[] { '[' }); System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text = array2[i]; if (text.Contains(']')) { string item = text.Substring(0, text.IndexOf(']')); if (!list.Contains(item)) { list.Add(item); } } } foreach (string current in list) { SASalaryBooksItem byId = this.saBooksItemService.GetById(current); if (byId.IsFormula) { if (string.IsNullOrEmpty(byId.Formula)) { formula = formula.Replace("[" + byId.Id + "]", "(0.000)"); } else { formula = formula.Replace("[" + byId.Id + "]", "(" + byId.Formula.ToString() + ")"); } } else { SASalaryItem byId2 = this.saItemService.GetById(byId.ItemId); if (byId2.Code == "TaxRate" || byId2.Code == "Deduct") { decimal taxrateDeduct = this.GetTaxrateDeduct(byId2.Code, level); formula = formula.Replace("[" + byId.Id + "]", taxrateDeduct.ToString("0.000")); } else { formula = formula.Replace("[" + byId.Id + "]", (!byId.DefaultValue.HasValue) ? "0.000" : byId.DefaultValue.Value.ToString("0.000")); } } } if (formula.Contains("[")) { formula = this.RepalceFormula(formula, --level); } } return(formula); }
private void AddData() { int month = System.Convert.ToInt32(this.ddlMonth.SelectedValue); int year = System.Convert.ToInt32(this.ddlYear.SelectedValue); string saBooksId = this.ddlSaBooks.SelectedValue; if (string.IsNullOrEmpty(saBooksId) || string.IsNullOrEmpty(month.ToString()) || string.IsNullOrEmpty(year.ToString())) { base.RegisterShow("系统提示", "生成失败,请先选择帐套,年份,月份!"); } string arg_52_0 = string.Empty; try { DataTable userInfoByDepartBooks = this.ptyhBll.GetUserInfoByDepartBooks(this.DepartmentId, saBooksId, year, month); // DataTable userInfoByDepartBooks = this.ptyhBll.GetUserInfoByDepartBooks(this.DepartmentId, year, month); System.Collections.Generic.List <SASalaryBooksItem> list = ( from sbi in this.saBooksItemService // where sbi.BooksId == saBooksId select sbi).ToList <SASalaryBooksItem>(); if (list.Count == 0) { base.RegisterShow("系统提示", "生成失败,该帐套下没有编辑帐套明细!"); } else { System.Collections.IEnumerator enumerator = userInfoByDepartBooks.Rows.GetEnumerator(); try { while (enumerator.MoveNext()) { DataRow dataRow = (DataRow)enumerator.Current; string userCode = dataRow["v_yhdm"].ToString(); string arg_158_0 = userCode; System.Collections.Generic.List <SASalaryBooksItem> list2 = ( from sbi in list where sbi.BooksId == saBooksId && !sbi.IsFormula select sbi).ToList <SASalaryBooksItem>(); foreach (SASalaryBooksItem saBooksItemNotFormula in list2) { if (( from sm in this.saMonthService where sm.Month == month && sm.Year == year && sm.UserCode == userCode && sm.ItemId == saBooksItemNotFormula.ItemId select sm).FirstOrDefault <SAMonthSalary>() == null) { SASalaryItem byId = this.saItemService.GetById(saBooksItemNotFormula.ItemId); if (byId.Code == "TaxRate" || byId.Code == "Deduct") { decimal?cost = null; cost = this.GetLastCost(userCode, saBooksItemNotFormula.ItemId); if (!cost.HasValue) { cost = new decimal?(this.GetTaxrateDeduct(byId.Code, 30)); } this.AddSaMonth(userCode, year, month, saBooksItemNotFormula.ItemId, cost); } else { decimal?cost2 = this.GetLastCost(userCode, saBooksItemNotFormula.ItemId); if (!cost2.HasValue) { cost2 = saBooksItemNotFormula.DefaultValue; } this.AddSaMonth(userCode, year, month, saBooksItemNotFormula.ItemId, cost2); } } } System.Collections.Generic.List <SASalaryBooksItem> list3 = ( from sbi in list where sbi.BooksId == saBooksId && sbi.IsFormula select sbi).ToList <SASalaryBooksItem>(); foreach (SASalaryBooksItem saBooksItemFormula in list3) { if (( from sm in this.saMonthService where sm.Month == month && sm.Year == year && sm.UserCode == userCode && sm.ItemId == saBooksItemFormula.ItemId select sm).FirstOrDefault <SAMonthSalary>() == null) { string formula = saBooksItemFormula.Formula; decimal?cost3 = null; if (!string.IsNullOrEmpty(formula)) { string expression = this.RepalceFormula(formula, 30); try { cost3 = this.GetLastCost(userCode, saBooksItemFormula.ItemId); if (!cost3.HasValue) { cost3 = new decimal?(CalculatorHelper.Calc(expression)); } } catch (System.Exception ex) { if (ex.Message == "计算错误") { cost3 = new decimal?(0m); } } } this.AddSaMonth(userCode, year, month, saBooksItemFormula.ItemId, cost3); } } } } finally { System.IDisposable disposable = enumerator as System.IDisposable; if (disposable != null) { disposable.Dispose(); } } } } catch (System.Exception) { base.RegisterShow("系统提示", "生成失败,请确认公式逻辑是否正确或者计算额度是否过大!"); } }
protected void gvwSaMonth_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); for (int i = 6; i < e.Row.Cells.Count; i++) { string text = e.Row.Cells[i].Text; string[] array = text.Split(new char[] { '⊙' }); e.Row.Cells[i].Text = array[0]; list.Add(array[1]); } if (list.Count > 0) { this.ViewState["colItemId"] = list; } } if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Attributes.Add("align", "right"); System.Collections.Generic.List <string> list2 = new System.Collections.Generic.List <string>(); list2 = (System.Collections.Generic.List <string>) this.ViewState["colItemId"]; e.Row.Attributes["id"] = this.gvwSaMonth.DataKeys[e.Row.RowIndex].Value.ToString(); e.Row.Cells[4].Attributes.Add("align", "center"); e.Row.Cells[5].Attributes.Add("align", "center"); string text2 = e.Row.Cells[4].Text; string text3 = e.Row.Cells[5].Text; for (int j = 6; j < e.Row.Cells.Count; j++) { string text4 = e.Row.Cells[j].Text; TextBox textBox = new TextBox(); HiddenField hiddenField = new HiddenField(); if (text4 == " ") { textBox.Text = "0.000"; hiddenField.Value = "0.000"; } else { textBox.Text = text4; hiddenField.Value = text4; } textBox.Width = 80; textBox.CssClass = "easyui-validatebox easyui-numberbox"; textBox.Style.Add("text-align", "right"); textBox.Attributes.Add("onblur", "computeValue(this);"); string itemId = list2[j - 6]; textBox.Attributes["itemId"] = itemId; hiddenField.ID = "hfld" + itemId; string booksId = this.ddlSaBooks.SelectedValue.Trim(); SASalaryBooksItem sASalaryBooksItem = ( from sbi in this.saBooksItemService where sbi.BooksId == booksId && sbi.ItemId == itemId select sbi).FirstOrDefault <SASalaryBooksItem>(); if (sASalaryBooksItem != null) { if (sASalaryBooksItem.IsFormula) { textBox.Attributes.Add("disabled", "disabled"); textBox.Attributes.Add("data-options", "min:-9999999999,max:9999999999999999,precision:3,groupSeparator:','"); } else { SASalaryItem byId = this.saItemService.GetById(itemId); if (byId != null) { if (byId.Code == "TaxRate" || byId.Code == "Deduct") { textBox.Attributes.Add("disabled", "disabled"); textBox.Attributes.Add("data-options", "min:-9999999999,max:9999999999999999,precision:3,groupSeparator:','"); } else { if (text3 == "是") { textBox.Attributes.Add("disabled", "disabled"); } if (text2 == "否") { textBox.Attributes.Add("disabled", "disabled"); } textBox.Attributes.Add("data-options", "min:0,max:9999999,precision:3,groupSeparator:','"); } } } } e.Row.Cells[j].Controls.Add(textBox); e.Row.Cells[j].Controls.Add(hiddenField); } } }