关闭

JS 工作随笔 07 关于JS提交表单的方式和与C#实现保存数据

125人阅读 评论(0) 收藏 举报
分类:

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">首先写JS</span>

var Save = function () {
            this.disable();
            var vJH = App.GP_Well.getSelectionModel().getSelection()[0].data.JH;
            var entcode = App.GP_Well.getSelectionModel().getSelection()[0].data.ENTCODE;
            Ext.MessageBox.confirm('操作提示', '确认保存井号[ ' + vJH + ' ]的基本信息吗?', function (button, text) {
                if (button == 'yes' && App.fp_Main.getForm().isValid()) {
                    var gpData = JSON.stringify(App.GP_Main.store.getChangedData());
                    $.post("Save", { Values: gpData, entcode: entcode, WellNumber: vJH }, function (result) {
                        result = eval('(' + result + ')');//<span id="w_28" high-light-id="w_10,w_28" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">JSON</span><span id="w_29" high-light-id="w_11,w_29" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">对象</span><span id="w_30" high-light-id="w_5,w_30" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">的</span><span id="w_31" high-light-id="w_6,w_31" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">字符串</span><span id="w_32" high-light-id="w_7,w_32" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">表示</span><span id="w_33" high-light-id="w_12,w_33" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">就会</span><span id="w_34" high-light-id="w_18,w_34" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">通过</span><span id="w_35" high-light-id="w_19,w_20,w_35" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">eval </span><span id="w_36" high-light-id="w_21,w_36" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">JavaScript</span><span id="w_37" high-light-id="w_22,w_37" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">函数</span><span id="w_38" high-light-id="w_13,w_14,w_38,w_39" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">转变</span><span id="w_39" high-light-id="w_13,w_14,w_38,w_39" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">成</span><span id="w_40" high-light-id="w_15,w_40,w_41" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">一</span><span id="w_41" high-light-id="w_15,w_40,w_41" class="high-light" style="color: rgb(245, 117, 39); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">个</span><span id="w_42" high-light-id="w_16,w_42" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">JavaScript</span><span id="w_43" high-light-id="w_17,w_43" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">对象</span><span id="w_44" high-light-id="w_23,w_44" style="color: rgb(51, 51, 51); font-family: arial, 宋体; font-size: 14px; line-height: 22px; background-color: rgb(249, 249, 249);">。</span>
                        if (result.MsgCode == '0000') {
                            App.S_Main.reload();
                            X.Msg.notify("操作提示", "操作成功!<br/>井号[ " + vJH + " ]的基本信息保存成功.");
                        } else {
                            X.Msg.show({ icon: X.MessageBox.ERROR, msg: result.Msg, buttons: X.Msg.OK });
                        }
                    });
                }
            });
            this.enable();
        };
其次写C#

 

 public string Save(string Values, string ENTCODE, string WellNumber)
        {
            int iCount = 0;
            try
            {
                JObject jo = (JObject)JsonConvert.DeserializeObject(Values);
                if (jo["Created"] != null)
                {
                    //获取当前井号是否存在测点序号CD_XH,如果存在取最大值,如果不存在从1开始保存
                    int iCD_XH = BLL_ZGJWJ_JJ.Init.GetCD_XH(WellNumber);
                    List<ZGJWJ_JJ> ss = JSON.Deserialize<List<ZGJWJ_JJ>>(jo["Created"].ToString());
                    foreach (var row in ss)
                    {
                        row.CD_XH = iCD_XH + 1;
                        row.JH = WellNumber;
                        row.INPUTTIME = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        row.USERNAME = DSU.USER_NAME;
                        row.USERCODE = DSU.ID;
                        row.ENTCODE = ENTCODE;
                        iCount += BLL_ZGJWJ_JJ.Init.Save(row);
                    }
                }
                if (jo["Updated"] != null)
                {
                    List<ZGJWJ_JJ> ss = JSON.Deserialize<List<ZGJWJ_JJ>>(jo["Updated"].ToString());
                    foreach (var row in ss)
                    {
                        row.JH = WellNumber;
                        row.INPUTTIME = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        row.USERNAME = DSU.USER_NAME;
                        row.USERCODE = DSU.ID;
                        iCount += BLL_ZGJWJ_JJ.Init.Modify(row);
                        if (iCount == 0)
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ReturnMsg.MsgCode = "9999";
                ReturnMsg.Msg = string.Format("系统错误:{0}", ex);
            }
            return JsonConvert.SerializeObject(ReturnMsg);
        }
ReturnMsg是在BASECONTROLA里面写入: protected AjaxResult ReturnMsg = new AjaxResult() { MsgCode = "0000", Msg = "" };构造函数

最后用oracle helper:返回影响数据行数

  

  public int Save(ZGJWJ_JJ row)
        {
            List<OracleParameter> LParams = new List<OracleParameter>();
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "jh", row.JH));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "entcode", row.ENTCODE));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "cd_xh", row.CD_XH));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "ksjs", row.KSJS));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "jsjs", row.JSJS));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "cljjy", row.CLJJY));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "cljje", row.CLJJE));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "pjjj", row.PJJJ));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "ztwj", row.ZTWJ));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "usercode", row.USERCODE));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "username", row.USERNAME));
            LParams.Add(OracleHelper.InParam(OracleDbType.Varchar2, "inputtime", row.INPUTTIME));
            Sql = "insert into ZGJWJ_JJ(jh,entcode,cd_xh,ksjs,jsjs,cljjy,cljje,pjjj,ztwj,usercode,username,inputtime)";
            Sql += "values(:jh,:entcode,:cd_xh,:ksjs,:jsjs,:cljjy,:cljje,:pjjj,:ztwj,:usercode,:username,:inputtime)";
            return OracleHelper.ExecuteNonQuery("ZJ", CommandType.Text, Sql, LParams.ToArray());
        }


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6063次
    • 积分:148
    • 等级:
    • 排名:千里之外
    • 原创:9篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类