示例#1
0
        /// <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;
                }
            }
        }
示例#2
0
        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 });
        }