1 2 3 4 5日历 6 7 8 9 10 11 12 13 14 15 16 17 18 192029 30 31 69 702128222324252627
var down=false; //判断鼠标是否处于down状态 var y=0;//对象top坐标 var t=0;//时间坐标 var h=0;//对象的height 高度 var w=0;//方向0向下1向下 var m=0;//移动的值 var current_obj, is_current_obj=false; //选择的对象 var current_date; //选择的时间 var resize_obj, resize_down=false; //改动大小的对象 var state_obj=false; var timer; //定时器 var old_employee_type=""; var old_employee_name=""; var old_employee_gh=""; var is_edit = false; var edit_div_id = ""; var showDialog_day =""; var getPageType=" "; // alert(getPageType); function setScrollTop(op){ if(!down) return var grid=_c(document,"div","wc-scrollable-grid"); if(op=="up"){ grid.scrollTop-=10; }else if(op=="down"){ grid.scrollTop+=10; //alert('ddddddddd'); } //_("tool").innerHTML=grid.scrollBottom; timer=setTimeout("setScrollTop('"+op+"')",100) } //删除未创建完成的对象 function del_current_obj(){ if(_(current_date+''+y+'_event_div')){ _(current_date+''+y+'_event_div').parentNode.removeChild(_(current_date+''+y+'_event_div')); } } function resize_downEvent(day,event){ resize_down=true; resize_obj=getEventObj(event).parentNode; } //窗体上鼠标点击释放触发事件 window.οnmοuseup=function(){ down=false; if(!state_obj) del_current_obj(); } var wc_scrollable_grid=false; var grid_tr=false; //窗体大小改变触发事件 window.οnresize=function(){ if(!wc_scrollable_grid) wc_scrollable_grid=_c(document,"div",'wc-scrollable-grid'); if(!grid_tr) grid_tr=_c(document,"tr","grid-tr"); if(_("tab_input").value=="month"){ //alert($(".Grid").width()*0.1429); //alert($(".CalendarWeekend").width()); $(".easyui-panel").each(function(){ $(this).panel('resize',{ width: $(".Grid").width()*0.1429, height: 0 }); }); for(var i=0 ;i) { grid_tr[i].style.height=(getWinHeight()-95)/5+'px'; } }else if(_("tab_input").value=="week"){ wc_scrollable_grid.style.height=(getWinHeight()-95)+'px'; }else if(_("tab_input").value=="day"){ wc_scrollable_grid.style.height=(getWinHeight()-69)+'px'; } } function showModalDialog(day, beginTime, endTime) { ////////////////////////////////////////////////// // getPageType = GetParameter('type'); // // alert(getPageType); createBlackBg(); this.dialog = _create('div'); this.dialog.className='dialog bs br10'; this.header = _create('div'); this.closeimg=_create('div'); this.bar=_create('div'); var lang=new Language(_('hidden_language').value); this.dialog.style.top=(getWinHeight()/2-120)+'px'; this.dialog.style.left=(getWinWidth()/2-200)+'px'; this.closeimg.className='close'; this.closeimg.innerHTML=""; this.bar.className='bar'; this.bar.innerHTML=lang.event; this.form=_create('form'); this.time=_create('div'); this.title=_create('div'); this.content=_create('div'); this.btu=_create('div'); var date=new Date(day); showDialog_day = date.format('yyyyMMdd'); this.time.innerHTML=lang.date+' '+date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+" (" + lang.weekArray[date.getDay()] + "), " + Time_hm[beginTime] + " – " + Time_hm[endTime]; //this.title.innerHTML = " "; this.title.innerHTML = get_employee_type_html(); this.content.innerHTML = "" + lang.title + ":
" + lang.content + ":" + get_datelist_html() + "
"; this.btu.innerHTML=""+""+" " + lang.edit_detail + ""; this.dialog.appendChild(this.bar); this.dialog.appendChild(this.closeimg); this.form.appendChild(this.time); this.form.appendChild(this.title); this.form.appendChild(this.content); this.form.appendChild(this.btu); this.dialog.appendChild(this.form); _('append').appendChild(this.dialog); //初始化表格中的数据 $("#state").combobox({ onChange: function () { var ttt = $("#state").combobox('getValue'); // var obj = [{ code: '1', name: 'xxxx', price: 12, check:1}]; $('#dg').datagrid('load', {s_key:ttt, website:'http://www.xxxx.cn/con.html'}); //$('#dg').datagrid('selectRow', 0); //设定itemid为0的选中 }, }); $('#dg').datagrid({ //url: 'datagrid_data.json', url: '../ScheduleWebService.asmx/GetProductInfo', queryParams:{s_key:$("#state").combobox('getValue'), website:'http://www.xxxx.cn/con.html' }, rownumbers: false, singleSelect: true, selectOnCheck: true, checkOnSelect: true, columns: [[ { field: 'check', title: 'check', checkbox: true, width: 50 }, { field: 'StaffNo', title: '工号', width: 100 }, { field: 'StaffName', title: '姓名', width: 100 }, { field: 'Staffxb', title: '性别', width: 60 }, { field: 'Staffdrzw', title: '担任职位', width: 80, align: 'right' } ]], editor: { type: 'checkbox', options: { on: 1, off: 0 } }, onLoadSuccess: function () {//加载完毕后获取所有的checkbox遍历 var date = $('#dg').datagrid('getRows'); var flag = false; for (var i = 0; i < date.length; i++) { // alert(date[i].name);//这里可以查看每一个值,通过这个,可以进行盘点,设定默认选择项 if (date[i].StaffNo == old_employee_gh) { $('#dg').datagrid('selectRow', i); flag = true; break; } } if (!flag) $('#dg').datagrid('selectRow', 0); } }); } function saveModalDialog(){ var selected = $('#dg').datagrid('getSelected'); //这个可以获取到当前选择的结果 //如果选择,则进行判断,是删除,还是修改== if (selected) { var type = $("#state").combobox('getValue'); var name = selected.StaffName; //动态计算可用的宽度,如果不够则减少title信息 var div_title = $('.CalendarWeekend.day_pc #event_list').width()>=140?(type+":"+name):name; var div_id = showDialog_day +'_'+selected.StaffNo;//DIV的ID为日期_数据库唯一编号来定 var gh = selected.StaffNo; //判定,如果是新增,则直接走新增div,如果现在的div_id不等于修改前的id,则删除掉修改之前的ID,然后隐藏DIV,增加新的div, //如果现在的div_id在页面中存在,且状态为显示,则提示该人员已经新增,否则,显示DIV,在数据库中增加该对象 //如果选择了人员,则div_id存在 if(document.getElementById(div_id)) { if (document.getElementById(div_id).parentNode.style.display == 'none') { $('#'+div_id).panel('open'); $('#'+div_id).panel('setTitle',div_title); //增加新增的节点信息,div_id AddSchedule(div_id); if(edit_div_id != "" && edit_div_id != div_id)//说明是修改,且ID不同 { $('#'+edit_div_id).panel('close'); //删除掉原有的数据 edit_div_id //DelSchedule(edit_div_id);//此处不用删除了,因为close函数会自动调用delete_employee方案 } closeModalDialog(); return; } else { alert("该人员已经添加,请重新选择!"); return ; } } else //该DIV 不存在且,是编辑状态 { if(edit_div_id != "" )//说明是修改 { $('#'+edit_div_id).panel('close'); //删除掉原有的数据 edit_div_id //DelSchedule(edit_div_id);//此处不用删除了,因为close函数会自动调用delete_employee方案 } } AddSchedule(div_id); //增加新增的节点信息 div_id if (edit_div_id == "") { //alert($('.CalendarWeekend.day_pc #event_list').val()); $('.CalendarWeekend.day_pc #event_list').append(""); } else { $("#"+ edit_div_id).parent().parent().append(""); } $('#'+div_id).panel( { title: div_title, content: type, width: $(".CalendarWeekend.day_pc #event_list").width(), height:0, padding:0, closable:true, onBeforeClose: function () { return delete_employee(name, type, div_id); }, tools:[{ iconCls:'icon-edit', handler:function(){ // alert('1'); edit_employee(name,type, div_id); } }] }); } //如果没有选择 else { alert("没有选择人员"); } closeModalDialog(); } //function AddSchedule()为保存函数,在选取成功后,将所选人员gh,和新生产div_id 传到后端,用于保存数据 function AddSchedule(div_id) { var date = div_id.split('_')[0]; var gh = div_id.split('_')[1]; try { $.ajax({ type: "POST", url: "../ScheduleWebService.asmx/AddSchedule", data: "{'date':'" + date + "','gh':'" + gh + "'}", contentType: "application/json; charset=utf-8;", success: CallSucceed, dataType: "json", async: false, //强制同步 failure: CallFailed }); } catch (e) { $.messager.alert('提示', 'failed to call web service. Error:' + e, 'error'); } } function CallSucceed(response) { alert(response.d); } function CallFailed(error) { $.messager.alert('提示', 'error: ' + error, 'error'); } //删除数据 function DelSchedule(div_id) { var date = div_id.split('_')[0]; var gh = div_id.split('_')[1]; var xm= xm; try { $.ajax({ type: "POST", url: "../ScheduleWebService.asmx/DelSchedule", data: "{'date':'" + date + "','gh':'" + gh + "'}", contentType: "application/json; charset=utf-8;", success: CallSucceed, async: false, //强制同步 dataType: "json", failure: CallFailed }); } catch (e) { $.messager.alert('提示', 'failed to call web service. Error:' + e, 'error'); } } //关闭选择页面 function closeModalDialog(){ _('append').innerHTML = ''; old_employee_name = ""; old_employee_type = ""; edit_div_id= ""; is_edit = false; } function createBlackBg() { this.bg=_create('div'); this.bg.className = 'blackBg'; _('append').appendChild(this.bg); } function get_datelist_html() { var out_str = ""; out_str += "; out_str += " \n"; out_str += " \n"; out_str += "
\n"; return out_str; } //编辑修改人员信息 function edit_employee(name, type, div_id) { // alert(name); old_employee_name = name; old_employee_type = type; old_employee_gh= div_id.split('_')[1]; is_edit = true; edit_div_id=div_id; var date = new Date(div_id.substring(0,4),div_id.substring(4,6)-1,div_id.substring(6,8)); //alert(date.toString()); showModalDialog(date.format('MM/dd/yyyy'), 18, 34); } //删除人员信息 function delete_employee(dept, name, div_id) { if (edit_div_id == "" && !confirm("确认要删除么?")) { return false; } DelSchedule(div_id); return true; } //动态分析不同部门显示各自部门的类型,没有定义部门的获取全面人员 function get_employee_type_html() { var getPageType= GetParameter('type'); //alert(getPageType); if (getPageType!="") { var visiabletype =Array(getPageType); } else { var visiabletype = new Array('行政部','护理科','后勤事务科','院领导','生活服务科'); } var EmployeeType=visiabletype; //自动适应生成人员选择的列表信息 var lang = new Language(_('hidden_language').value); var out_str = "" + lang.title + ":event.js
var staff_type = ""; Calendar.prototype.header = function () { this.c_h_tb = _create('table'); this.c_h_tbody = _create('tbody'); this.c_h_tb_tr = _create('tr'); this.c_h_tb_td_l = _create('td'); this.c_h_tb_th = _create('th'); this.c_h_tb_td_c = _create('td'); this.c_h_tb_td_r = _create('td'); this.c_h_tb_td_img = _create('img'); this.c_h_tb_td_img2 = _create('img'); this.c_h_tb.className = 'Header'; this.c_h_tb.cellspacing = '0'; this.c_h_tb.cellpadding = '0'; this.c_h_tb.border = '0'; this.c_h_tb_td_l.className = 'HeaderLeft'; this.c_h_tb_td_r.className = 'HeaderRight'; this.c_h_tb_td_img.src = 'images/Spacer.gif'; this.c_h_tb_td_img2.src = 'images/Spacer.gif'; this.c_h_tb_td_c.className = 'tbg'; this.hid = _create('input'); this.hid_rday = _create('input'); this.hid_rday.type = 'hidden'; this.hid_rday.id = 'rday'; this.hid.type = 'hidden'; this.hid.value = this.date.format("MM/dd/yyyy"); this.hid.id = 'date'; if (this.language.type == 'chinese') { this.c_h_tb_th.innerHTML = '' + (this.date.getFullYear()) + ' ' + this.language.year + ' ' + (this.date.getMonth() + 1) + ' ' + this.language.month; } else { this.c_h_tb_th.innerHTML = (this.date.getFullYear()) + ' ' + this.language.monthArray[this.date.getMonth()]; } this.prevMonth_div = _create('div'); this.nextMonth_div = _create('div'); this.prevMonth_div.className = 'prevMonth'; this.nextMonth_div.className = 'nextMonth'; ////////打印 this.printDiv = _create("div"); this.printDiv.className = 'nextMonth'; addEvents(this.printDiv, 'click', PrintForm); //////// addEvents(this.prevMonth_div, 'click', Prev); addEvents(this.nextMonth_div, 'click', Next); this.c_h_tb_td_l.appendChild(this.c_h_tb_td_img); this.c_h_tb_td_r.appendChild(this.c_h_tb_td_img2); this.c_h_tb_sz = _create('a'); this.c_h_tb_sz.className = 'c_sz'; this.c_h_tb_td_c.appendChild(this.c_h_tb_sz); this.c_h_tb_td_c.appendChild(this.hid); this.c_h_tb_td_c.appendChild(this.hid_rday); this.c_h_tb_th.appendChild(this.prevMonth_div); this.c_h_tb_th.appendChild(this.nextMonth_div); this.c_h_tb_tr.appendChild(this.c_h_tb_td_l); this.c_h_tb_th.appendChild(this.printDiv); // this.c_h_tb_th.appendChild(this.prevMonth_div); //this.c_h_tb_th.appendChild(this.nextMonth_div); this.c_h_tb_tr.appendChild(this.c_h_tb_th); this.c_h_tb_tr.appendChild(this.c_h_tb_td_c); this.c_h_tb_tr.appendChild(this.c_h_tb_td_r); this.c_h_tbody.appendChild(this.c_h_tb_tr); this.c_h_tb.appendChild(this.c_h_tbody); this.content.appendChild(this.c_h_tb); } function PrintForm() { window.open('Print_Schedule.htm', 'print', 'toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } Calendar.prototype.list = function () { this.c_h_tb = _create('table'); this.c_h_tbody = _create('tbody'); this.c_h_tb_tr_top = _create('tr'); this.c_h_tb_td_top = _create('td'); this.c_h_tb_td_top.valign = 'top'; this.c_h_tb.className = 'Calendar'; this.grid = new GridList(this.date, this.language); this.c_h_tb_td_top.appendChild(this.grid); this.c_h_tb_tr_top.appendChild(this.c_h_tb_td_top); this.c_h_tbody.appendChild(this.c_h_tb_tr_top); this.c_h_tb.appendChild(this.c_h_tbody); this.content.appendChild(this.c_h_tb); flush_current_schedule(this.date.getFullYear(), this.date.getMonth() + 1); } //日历 单元格子天的集合 var GridList = function (date, language) { this.c_g_tb = _create('table'); this.c_g_tbody = _create('tbody'); this.c_g_tb.className = 'Grid'; //5行 this.day = 0; //1-31天 this.date = new Date(date.format("MM/01/yyyy")); this.w = this.date.getDay(); this.year = this.date.getFullYear(); this.month = this.date.getMonth(); this.days = 0; this.days = getDayNumByYearMonth(this.year, this.month); this.week = language.weekArray; this.ndate = new Date(); var H = parseInt(400) / 5; for (var i = 0; i < 6; i++) { this.c_g_tr = _create('tr'); if (i == 0) { //7列 for (var j = 0; j < 7; j++) { this.c_g_td = _create('td'); this.c_g_td.className = 'CalendarWeekendName'; this.c_g_td.style.width = '14.29%'; this.c_g_td.innerHTML = this.week[j]; this.c_g_td.style.background = '#eee'; this.c_g_tr.appendChild(this.c_g_td); } } else { this.c_g_tr.className = "grid-tr"; this.c_g_tr.style.height = (getWinHeight() - 95) / 5 + 'px'; for (var j = 0; j < 7; j++) { var gtd = new Grid_td(language, this.year, this.month, this.day, this.date, this.ndate, i, j, this.w, this.days); this.day = gtd.day; this.c_g_tr.appendChild(gtd.c_g_td); } } this.c_g_tbody.appendChild(this.c_g_tr); } this.c_g_tb.appendChild(this.c_g_tbody); return this.c_g_tb; } var Grid_td = function (language, year, month, day, date, ndate, i, j, w, days) { this.c_g_td = _create('td'); this.c_g_td.className = 'CalendarWeekend'; this.c_g_td.style.verticalAlign = 'top'; this.c_g_td.style.textAlign = 'left'; this.day; var g = ''; var event_div = get_event_div(year, month, day); if (i == 1 && j >= w) { day++; var lunarhtml = ''; if (language.type == 'chinese') { var lunar = lunarday((month + 1) + '//' + day + '//' + year); var lunarhtml = " " + lunar + ""; } this.c_g_td.id = 'day_' + day; var g = ""; } else if (i > 1 && day < days) { day++; var lunarhtml = ''; if (language.type == 'chinese') { var lunar = lunarday((month + 1) + '//' + day + '//' + year); var lunarhtml = " " + lunar + ""; } this.c_g_td.id = 'day_' + day; var g = ""; } else { var g = " " this.c_g_td.style.background = '#eeeeee'; } addEvents(this.c_g_td, 'click', function () { get_day(day) }); this.day = day; this.c_g_td.innerHTML = g; if (isToday(date.format('MM/' + day + '/yyyy'))) { this.c_g_td.className += " today"; } return this; } //该函数可以完成初始化 function get_event_div(year, month, day) { return ""; //""+year+":"+month; } // function addevent(day) { var url = '?do=subject.view&op=add'; var d = _('date'); var date = new Date(d.value); var d_day = day > 9 ? day : '0' + day; var d_month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1); var time = '&sdate=' + date.getFullYear() + '-' + d_month + '-' + d_day; // alert(time); //showdialog('添加课程',url+time); goto(url + time); } // function get_day(day) { if (!_('day_' + day)) return; _('day_' + day).addClass('day_pc'); var rday = _("rday"); var d = rday.value; _("add_" + day).style.display = 'block'; //clickDay(d_a[1]); var da = _('date'); var date = new Date(da.value); var month = date.getMonth() + 1; var year = date.getFullYear(); if (d) { if (d != ('day_' + day)) { _(d).removeClass('day_pc'); var d_a_l = d.split("_"); _("add_" + d_a_l[1]).style.display = 'none'; _("rday").value = 'day_' + day; } } else { _("rday").value = 'day_' + day; } // 通过url得到 一天的事件 //var url='?do=subject.getDay&year='+year+'&month='+month+'&date='+d_a[1]; //getDayEventsByJson(url); } //显示点击的一天课程 clickDay = function (day) { var t = _("eventbyDay"); var d = _('date'); var date = new Date(d.value); t.innerHTML = (date.getMonth() + 1) + "月" + day + "日"; } //下一个月 Next = function () { var d = _('date'); var date = new Date(d.value); date.addMonths(1); gotoMonth(date); } //上一个月 Prev = function () { var d = _('date'); var date = new Date(d.value); date.addMonths(-1); gotoMonth(date); } //跳转到某月 var gotoMonth = function (date) { var lang = 'english'; var languageobj = _('hidden_language'); if (languageobj) { lang = languageobj.value; } try { var cr = new Calendar(); cr.date = date; cr.language = new Language(lang); cr.load(); } catch (e) { alert(e); } } function flush_current_schedule(year, month) { try { $.ajax({ type: "POST", url: "../ScheduleWebService.asmx/GetSchedule", data: "{'year':'" + year + "','month':'" + month+ "'}", contentType: "application/json; charset=utf-8;", success: getScheduleCallSucceed, dataType: "json", failure: getScheduleCallFailed }); } catch (e) { $.messager.alert('提示', 'failed to call web service. Error:' + e, 'error'); } function getScheduleCallSucceed(response) { var res_array = eval('(' + response.d + ')'); if (res_array.length > 0) { for (var i = 0; i < res_array.length; i++) { var date = res_array[i].ScheduleDate; var gh = res_array[i].ScheduleGh; var name = res_array[i].ScheduleXm; var getStaffType = GetParameter('type'); getStaffType = decodeURIComponent(getStaffType); // alert(getStaffType); var type = res_array[i].ScheduleType; if (type != getStaffType) { continue; } //alert(type); var div_id = date + "_" + gh; var div_title = $('#event_list').width() >= 140 ? (type + ":" + name) : name; var day = date.substring(6, 8); //alert(div_title); if (day.indexOf("0") == 0) { day = day.substring(1,2); } $("#day_" + day + " #event_list").append(""); getScheduleCallSucceed2(date, gh, name,div_id, div_title, type, day); } } } function getScheduleCallFailed(error) { $.messager.alert('提示', 'error: ' + error, 'error'); } } //页面初始化 function getScheduleCallSucceed2(date, gh, name,div_id,div_title, type, day) { $('#' + div_id).panel( { title: div_title, content: type, width: $(" #event_list").width(), height: 0, padding: 0, closable: true, onBeforeClose: function () { return delete_employee(name, type, div_id); }, tools: [{ iconCls: 'icon-edit', handler: function () { edit_employee(name, type, div_id); } }] }); }
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Web; 5 using System.Web.Services; 6 using System.Web.SessionState; 7 using System.Web.Script.Services; 8 using System.Runtime.Serialization.Json; 9 using System.IO; 10 using System.Text; 11 using System.Data.SqlClient; 12 13 14 [WebService(Namespace = "http://tempuri.org/")] 15 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 16 // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 17 [System.Web.Script.Services.ScriptService] 18 19 public class ScheduleWebService : System.Web.Services.WebService, IRequiresSessionState 20 { 21 22 public ScheduleWebService () { 23 24 //如果使用设计的组件,请取消注释以下行 25 //InitializeComponent(); 26 } 27 28 public class ProductInfo 29 { 30 31 private string staffName = string.Empty; 32 ///33 /// 商品名称 34 /// 35 public string StaffName 36 { 37 get { return this.staffName; } 38 set { this.staffName = value; } 39 } 40 private string staffNo = string.Empty; 41 /// 42 /// 商品编号 43 /// 44 public string StaffNo 45 { 46 get { return this.staffNo; } 47 set { this.staffNo = value; } 48 } 49 private string staffxb; 50 /// 51 /// 商品价格 52 /// 53 public string Staffxb 54 { 55 set { this.staffxb = value; } 56 get { return this.staffxb; } 57 } 58 private string staffdrzw; 59 /// 60 /// 库存数量 61 /// 62 public string Staffdrzw 63 { 64 set { this.staffdrzw = value; } 65 get { return this.staffdrzw; } 66 } 67 public ProductInfo(string staffNo, string staffName, string staffxb, string staffdrzw) 68 { 69 // this.pictureUrl = pictureUrl; 70 this.staffName = staffName; 71 this.staffNo = staffNo; 72 this.staffxb = staffxb; 73 this.staffdrzw = staffdrzw; 74 } 75 public ProductInfo() 76 { } 77 } 78 79 80 81 82 public class ScheduleInfo 83 { 84 85 private string scheduleDate = string.Empty; 86 private string scheduleGh = string.Empty; 87 private string scheduleXm = string.Empty; 88 private string scheduleType = string.Empty; 89 90 public string ScheduleDate 91 { 92 get { return this.scheduleDate; } 93 set { this.scheduleDate = value; } 94 } 95 96 public string ScheduleGh 97 { 98 get { return this.scheduleGh; } 99 set { this.scheduleGh = value; } 100 } 101 102 public string ScheduleXm 103 { 104 get { return this.scheduleXm; } 105 set { this.scheduleXm = value; } 106 } 107 108 public string ScheduleType 109 { 110 get { return this.scheduleType; } 111 set { this.scheduleType = value; } 112 } 113 public ScheduleInfo(string scheduleDate, string scheduleGh, string scheduleXm, string scheduleType) 114 { 115 // this.pictureUrl = pictureUrl; 116 this.scheduleDate = scheduleDate; 117 this.scheduleGh = scheduleGh; 118 this.scheduleXm = scheduleXm; 119 this.scheduleType = scheduleType; 120 } 121 public ScheduleInfo() 122 { } 123 } 124 125 126 /// 127 /// 获取商品信息 128 /// 129 /// 130 public string GetProductInfo2(string s_key) 131 { 132 try 133 { 134 List productInfo = new List (); 135 DataContractJsonSerializer jsonSer = new DataContractJsonSerializer(productInfo.GetType()); 136 MemoryStream ms = new MemoryStream(); 137 SqlConnection conn = new SqlConnection("server=server-111;database=BaseApp_V2.1_AXJ;uid=sa;pwd=trilink123!@#"); 138 conn.Open(); 139 SqlCommand cmd = new SqlCommand(@"select gh,xm,xb,drzw from S_rsygda where sbm='" + s_key + "'", conn); 140 141 //dataOperate = new CommonDataOperate(); 142 //reader = dataOperate.GetSqlDataReaderBySql("exec Get_AddProductInfo_Proc"); 143 SqlDataReader reader = cmd.ExecuteReader(); 144 while (reader.Read()) 145 { 146 productInfo.Add(new ProductInfo(reader.GetString(0), reader.GetString(1), reader.GetString(2), reader.GetString(3))); 147 //productInfo.Add(new ProductInfo("test", "123456", "张麻子", 12, 345)); 148 //productInfo.Add(new ProductInfo("test", "654321", "李四", 34, 123)); 149 } 150 jsonSer.WriteObject(ms, productInfo); 151 string result = Encoding.UTF8.GetString(ms.ToArray()); 152 153 ms.Close(); 154 return getJsonStr(productInfo); 155 //return result; 156 } 157 catch (Exception ex) 158 { 159 throw new Exception(ex.Message, ex); 160 } 161 } 162 163 164 [WebMethod] 165 public void GetProductInfo(string s_key, string website) 166 { 167 168 Context.Response.Write(GetProductInfo2(s_key)); 169 170 171 } 172 173 [WebMethod] 174 public string AddSchedule(string date, string gh) 175 { 176 177 try 178 { 179 List saveModalDialog = new List (); 180 List resultFlags = new List (); 181 ResultFlag resultFlag = default(ResultFlag); 182 resultFlag = new ResultFlag(); 183 SqlConnection conn = new SqlConnection("server=server-111;database=BaseApp_V2.1_AXJ;uid=sa;pwd=trilink123!@#"); 184 conn.Open(); 185 SqlCommand cmd = new SqlCommand(@"INSERT INTO S_ygdapbb ([date],[gh]) VALUES ('" + date + "', '" + gh + "')", conn); 186 187 int i = cmd.ExecuteNonQuery(); 188 189 if (i > 0) 190 { 191 192 return getJsonStr("保存成功"); 193 } 194 else 195 { 196 return getJsonStr("保存失败,请重新尝试"); 197 } 198 } 199 catch (Exception ex) 200 { 201 throw new Exception(ex.Message, ex); 202 } 203 204 } 205 206 207 [WebMethod] 208 public string DelSchedule(string date, string gh) 209 { 210 211 try 212 { 213 List saveModalDialog = new List (); 214 List resultFlags = new List (); 215 ResultFlag resultFlag = default(ResultFlag); 216 resultFlag = new ResultFlag(); 217 SqlConnection conn = new SqlConnection("server=server-111;database=BaseApp_V2.1_AXJ;uid=sa;pwd=trilink123!@#"); 218 conn.Open(); 219 SqlCommand cmd = new SqlCommand(@"delete from S_ygdapbb where [date] = '"+date+"' and [gh] = '"+gh+"';", conn); 220 221 int i = cmd.ExecuteNonQuery(); 222 223 if (i > 0) 224 { 225 226 return getJsonStr("删除成功"); 227 } 228 else 229 { 230 return getJsonStr("删除失败,请重新尝试"); 231 232 } 233 234 235 } 236 catch (Exception ex) 237 { 238 throw new Exception(ex.Message, ex); 239 } 240 241 } 242 243 [WebMethod] 244 public string GetSchedule(string year, string month) 245 { 246 DateTime dt = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month),1); 247 string start_time = dt.ToShortDateString(); 248 string end_time = dt.AddMonths(1).ToShortDateString(); 249 List scheduleList = new List (); 250 try 251 { 252 List saveModalDialog = new List (); 253 List resultFlags = new List (); 254 ResultFlag resultFlag = default(ResultFlag); 255 resultFlag = new ResultFlag(); 256 SqlConnection conn = new SqlConnection("server=server-111;database=BaseApp_V2.1_AXJ;uid=sa;pwd=trilink123!@#"); 257 conn.Open(); 258 SqlCommand cmd = new SqlCommand(@"select S_ygdapbb.[date],S_ygdapbb.gh,S_rsygda.xm,S_rsygda.sbm from S_ygdapbb,S_rsygda where ([date] >= '" + start_time + "' and [date] < '" + end_time + "') and S_rsygda.gh=S_ygdapbb.gh;", conn); 259 260 SqlDataReader reader = cmd.ExecuteReader(); 261 262 while (reader.Read()) 263 { 264 string ttt = reader.GetDateTime(0).ToString("yyyyMMdd"); 265 scheduleList.Add(new ScheduleInfo(reader.GetDateTime(0).ToString("yyyyMMdd"), reader.GetString(1), reader.GetString(2), reader.GetString(3))); 266 267 } 268 269 return getJsonStr(scheduleList); 270 271 272 273 274 } 275 catch (Exception ex) 276 { 277 278 return getJsonStr(scheduleList); 279 } 280 281 } 282 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 283 public string getJsonStr(object obj) 284 { 285 DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); 286 MemoryStream ms = new MemoryStream(); 287 serializer.WriteObject(ms, obj); 288 string jsonString = Encoding.UTF8.GetString(ms.ToArray()); 289 ms.Close(); 290 return jsonString; 291 } 292 293 294 }
转载于:https://www.cnblogs.com/wolf-620/archive/2013/05/28/3102998.html