public static string GetData(string R_YEAR) { try { RevenueBLL rvBLL = new RevenueBLL(); DataTable dt; string jsonString = string.Empty; dt = rvBLL.GetRevenueData(R_YEAR); // Convert to json string and Dispose if (dt != null) { jsonString = JsonHelper.DataTableToJson(dt); dt.Dispose(); dt = null; } rvBLL = null; return(jsonString); } catch (Exception) { throw; } }
public object AddRevenue(string oper, string id, string revenueYear, decimal revenueAmt, string remark) { try { RevenueBLL rvBLL = new RevenueBLL(); string msg; bool result = false; result = rvBLL.AddRevenueData(revenueYear, revenueAmt, remark); if (result) { msg = "Successfully"; } else { msg = "Failed"; } rvBLL = null; return(new { message = msg, title = "AddData" }); } catch (Exception) { throw; } }
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] //, UseHttpGet = false)] public object AddRevenue() //string revenueYear)//, float revenueAmt, string remark) { try { RevenueBLL rvBLL = new RevenueBLL(); string msg; bool result = false; result = rvBLL.AddRevenueData("111", 0, "123");//revenueYear, revenueAmt, remark); if (result) { msg = "Add Successfully"; } else { msg = "Add Failed"; } rvBLL = null; return(new { message = msg, title = "AddData" }); } catch (Exception) { throw; } }
public static object SaveDapper(string act, string index, string param) { //param 格式 [{"name":"R_YEAR","value":"1234"},{"name":"REVENUE","value":"2000"},{"name":"REMARK","value":"dfjdkfd"}] string type = "", message = ""; try { DataTable dtParam = JsonHelper.JsonToDataTable(param); int rId = string.IsNullOrEmpty(index) ? 0 : Convert.ToInt32(index); string revenueYear = string.IsNullOrEmpty(param) ? "" : GetValueByName(dtParam, "R_YEAR"); decimal revenueAmt = string.IsNullOrEmpty(param) ? 0 : Convert.ToDecimal(GetValueByName(dtParam, "REVENUE")); string remark = string.IsNullOrEmpty(param) ? "" : GetValueByName(dtParam, "REMARK"); RevenueBLL rvBLL = new RevenueBLL(); bool result = false; result = rvBLL.SaveRevenueDataDapper(act, rId, revenueYear, revenueAmt, remark); type = "Success"; message = result ? act + " Successfully" : act + " Failed"; rvBLL = null; } catch (Exception ex) { type = "Error"; message = ex.Message; } return(new { type = type, message = message }); }
public static string getRevenueJSON(string rYear) { RevenueBLL rvBLL = new RevenueBLL(); DataTable dt = rvBLL.GetRevenueData(rYear, "", ""); rvBLL = null; return(JsonHelper.DataTableToJson(dt)); }
private DataTable getRevenueData(string rYear, string createDateFrom, string createDateTo) { RevenueBLL rvBLL = new RevenueBLL(); DataTable dt = rvBLL.GetRevenueData(rYear, createDateFrom, createDateTo); rvBLL = null; return(dt); }
private void GetRYear() { try { RevenueBLL rvBLL = new RevenueBLL(); DataTable dt = rvBLL.GetRYear(); ddlRYear.DataTextField = "R_YEAR"; ddlRYear.DataValueField = "R_YEAR"; ddlRYear.DataSource = dt; ddlRYear.DataBind(); ddlRYear.Items.Insert(0, new ListItem(string.Empty, string.Empty)); } catch (Exception) { throw; } }
public static string QueryDapper(string rYear, string createDateFrom, string createDateTo) { // WebMethod 不在asp.net 的live cycle生命週期中, 所以不能控制page control(如text box等等) // 且一定要static, 因為可以不用真的有一個instance, 就可以執行 RevenueBLL rvBLL = new RevenueBLL(); //rYear若是用string[]或List<string> 會有殘存的問題, 如第一次 [123,234,345] , 第二次 [123,345] 但卻收到 [123,345,345] //string strYear = string.Empty; //if (rYear[0] == "") // strYear = ""; //else // strYear = string.Join(",", rYear); Console.WriteLine(rYear); string jsonString = JsonHelper.ObjToJson(rvBLL.GetRevenueDataDapper(rYear, createDateFrom, createDateTo)); return(jsonString); }
public static string Query(string rYear, string createDateFrom, string createDateTo) { //有資料庫修改以下程式即可 //DataTable dt = new DataTable(); //string sql = @"select * from table"; //dt = GetFromDB(sql); //string jsonStr = ""; //if (dt != null) // jsonStr = Util.JsonHelper.DataTableToJson(dt); //if (dt != null) //{ // dt.Dispose(); // dt = null; //} //return jsonStr; RevenueBLL rvBLL = new RevenueBLL(); DataTable dt; string jsonString = string.Empty; dt = rvBLL.GetRevenueData(rYear, createDateFrom, createDateTo); // Convert to json string and Dispose if (dt != null) { jsonString = JsonHelper.DataTableToJson(dt); dt.Dispose(); dt = null; } rvBLL = null; return(jsonString); //return Source; }
/// <summary> /// /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { //不让浏览器缓存 //context.Response.Buffer = true; //context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1); //context.Response.AddHeader("pragma", "no-cache"); //context.Response.AddHeader("cache-control", ""); //context.Response.CacheControl = "no-cache"; //context.Response.ContentType = "text/plain"; context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); NameValueCollection forms = context.Request.Form; string strOperation = forms.Get("oper"); string strResponse = string.Empty; if (strOperation == null) //oper = null which means its first load. { ////1.get the sample data //DataTable dt = GetAccountInfo(); ////2.convert to json //string jsonRes = GetJson(dt); //context.Response.Write(jsonRes); } else if (strOperation == "del") { try { int rId = Convert.ToInt16(forms.Get("rID")); RevenueBLL rvBLL = new RevenueBLL(); bool result = false; result = rvBLL.DeleteRevenueData(rId); if (!result) { strResponse = "Failed"; } rvBLL = null; context.Response.Write(strResponse); } catch (Exception ex) { context.Response.Write(ex.ToString()); //MessageBox.Show(ex.ToString()); //throw; } } else if (strOperation == "add") { try { string rYear = forms.Get("R_YEAR").ToString(); //float revenue = Convert.ToSingle(forms.Get("REVENUE")); decimal revenue = Convert.ToDecimal(forms.Get("REVENUE")); string remark = forms.Get("REMARK").ToString(); RevenueBLL rvBLL = new RevenueBLL(); bool result = false; result = rvBLL.AddRevenueData(rYear, revenue, remark); if (!result) { strResponse = "Failed"; } rvBLL = null; context.Response.Write(strResponse); } catch (Exception ex) { context.Response.Write(ex.ToString()); //MessageBox.Show(ex.ToString()); //throw; } } // strOperation == "edit" else { try { int rId = Convert.ToInt16(forms.Get("rID")); string rYear = forms.Get("R_YEAR").ToString(); //float revenue = Convert.ToSingle(forms.Get("REVENUE")); //float revenue = float.Parse(forms.Get("REVENUE"), NumberStyles.Any); decimal revenue = Convert.ToDecimal(forms.Get("REVENUE")); string remark = forms.Get("REMARK").ToString(); RevenueBLL rvBLL = new RevenueBLL(); bool result = false; result = rvBLL.EditRevenueData(rId, rYear, revenue, remark); if (!result) { strResponse = "Failed"; } rvBLL = null; context.Response.Write(strResponse); } catch (Exception ex) { context.Response.Write(ex.ToString()); //MessageBox.Show(ex.ToString()); //throw; } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { lbLanguage.Text = Page.UICulture;//查看網頁的語系 #region ddl binding ddlArea.DataTextField = "AreaName"; ddlArea.DataValueField = "AreaName"; ddlArea.DataSource = getAreaData(); ddlArea.DataBind(); ddlArea.Items.Insert(0, new ListItem { Text = "請選擇", Value = "" }); ddlCityName.DataTextField = "CityName"; ddlCityName.DataValueField = "CityName"; ddlCityName.DataSource = getCityData(); ddlCityName.DataBind(); ddlCityName.Items.Insert(0, new ListItem { Text = "全部", Value = "" }); DataTable dtStore = getStoreData(""); for (int i = 0; i < dtStore.Rows.Count; i++) { ddlStore.Items.Add(new ListItem(string.Format("{0}({1})", dtStore.Rows[i]["StoreName"].ToString(), dtStore.Rows[i]["CityName"].ToString()), dtStore.Rows[i]["StoreNo"].ToString())); } ddlStore.Items.Insert(0, new ListItem { Text = "全部", Value = "" }); ddlProdGroup.DataTextField = "ProdGroup"; ddlProdGroup.DataValueField = "ProdGroup"; ddlProdGroup.DataSource = GetProdGroup(); ddlProdGroup.DataBind(); ddlProdGroup.Items.Insert(0, new ListItem { Text = "全部", Value = "" }); RevenueBLL rvBLL = new RevenueBLL(); DataTable dt = rvBLL.GetRYear(); ddlRevenueYear.DataTextField = "R_YEAR"; ddlRevenueYear.DataValueField = "R_YEAR"; ddlRevenueYear.DataSource = dt; ddlRevenueYear.DataBind(); ddlYearSingle.DataTextField = "R_YEAR"; ddlYearSingle.DataValueField = "R_YEAR"; ddlYearSingle.DataSource = dt; ddlYearSingle.DataBind(); ddlYearSingle.Items.Insert(0, new ListItem { Text = "", Value = "" }); ddlYearMultiple.DataTextField = "R_YEAR"; ddlYearMultiple.DataValueField = "R_YEAR"; ddlYearMultiple.DataSource = dt; ddlYearMultiple.DataBind(); //ddlYearMultiple.Items.Insert(0, new ListItem { Text = "Select an option", Value = "-1" }); #endregion //btnEnableTab.ToolTip = "Save Data"; this.hdnParameterA.Value = "Y"; this.hdnParameterB.Value = JsonHelper.DataTableToJson(getRevenueData("", "", "")); } }
public static object Save(string act, string index, string param) { //param 格式 [{"name":"R_YEAR","value":"1234"},{"name":"REVENUE","value":"2000"},{"name":"REMARK","value":"dfjdkfd"}] string type = "", message = ""; try { //DataTable dtSource = JsonHelper.JsonToDataTable(Source); DataTable dtParam = JsonHelper.JsonToDataTable(param); RevenueBLL rvBLL = new RevenueBLL(); bool result = false; if (act == "Add") { //DataRow dr = dtSource.NewRow(); //dr["index"] = dtSource.Rows.Count > 0 ? (dtSource.AsEnumerable().Max(a => int.Parse(a["index"].ToString())) + 1).ToString() : "1"; //dr["col1"] = GetValueByName(dtParam, "col1"); //dr["col2"] = GetValueByName(dtParam, "col2"); //dr["col3"] = GetValueByName(dtParam, "col3"); //dtSource.Rows.Add(dr); string revenueYear = GetValueByName(dtParam, "R_YEAR"); decimal revenueAmt = Convert.ToDecimal(GetValueByName(dtParam, "REVENUE")); string remark = GetValueByName(dtParam, "REMARK"); result = rvBLL.AddRevenueData(revenueYear, revenueAmt, remark); message = result ? "Add Successfully" : "Add Failed"; rvBLL = null; } else if (act == "Mod") { //var row = dtSource.AsEnumerable().Where(a => a["index"].ToString() == index); //if (row != null) //{ // row.First()["col1"] = GetValueByName(dtParam, "col1"); // row.First()["col2"] = GetValueByName(dtParam, "col2"); // row.First()["col3"] = GetValueByName(dtParam, "col3"); //} int rId = Convert.ToInt32(index); string revenueYear = GetValueByName(dtParam, "R_YEAR"); decimal revenueAmt = Convert.ToDecimal(GetValueByName(dtParam, "REVENUE")); string remark = GetValueByName(dtParam, "REMARK"); //RevenueBLL rvBLL = new RevenueBLL(); //bool result = false; result = rvBLL.EditRevenueData(rId, revenueYear, revenueAmt, remark); message = result ? "Modify Successfully" : "Modify Failed"; rvBLL = null; } else if (act == "Del") { //var row = dtSource.AsEnumerable().Where(a => a["index"].ToString() == index); //if (row != null) //{ // dtSource.Rows.Remove(row.First()); // dtSource.AcceptChanges(); //} int rId = Convert.ToInt32(index); //RevenueBLL rvBLL = new RevenueBLL(); //bool result = false; result = rvBLL.DeleteRevenueData(rId); message = result ? "Delete Successfully" : "Delete Failed"; rvBLL = null; } //Source = JsonHelper.DataTableToJson(dtSource); type = "Success"; } catch (Exception ex) { type = "Error"; message = ex.Message; } return(new { type = type, message = message }); }