$PBExportHeader$uo_calendar_small.sru $PBExportComments$日历控件用户对象 forward global type uo_calendar_small from userobject end type type cb_ok from commandbutton within uo_calendar_small end type type cb_exit from commandbutton within uo_calendar_small end type type em_year from editmask within uo_calendar_small end type type pb_ok from picturebutton within uo_calendar_small end type type pb_ddlb from picturebutton within uo_calendar_small end type type dw_cal from datawindow within uo_calendar_small end type type ddlb_month from dropdownlistbox within uo_calendar_small end type end forward global type uo_calendar_small from userobject integer width = 887 integer height = 820 long backcolor = 80263328 long tabtextcolor = 33554432 event ue_close ( ) cb_ok cb_ok cb_exit cb_exit em_year em_year pb_ok pb_ok pb_ddlb pb_ddlb dw_cal dw_cal ddlb_month ddlb_month end type global uo_calendar_small uo_calendar_small type variables Int ii_Day, ii_Month, ii_Year String is_old_column String is_DateFormat end variables forward prototypes public function integer days_in_month (integer month, integer year) public subroutine enter_day_numbers (integer ai_start_day_num, integer ai_days_in_month) public function int get_month_number (string as_month) public function integer unhighlight_column (string as_column) public subroutine set_date (date ad_date) public subroutine set_date_format (string as_date_format) public subroutine draw_month (integer year, integer month) public subroutine init_cal (date ad_start_date) public function integer highlight_column (string as_column) end prototypes event ue_close();closewithreturn(parent,string(id_date_selected,'yyyymmdd')) //userself end event public function integer days_in_month (integer month, integer year);//Most cases are straight forward in that there are a fixed number of //days in 11 of the 12 months. February is, of course, the problem. //In a leap year February has 29 days, otherwise 28. Integer li_DaysInMonth, li_Days[12] = {31,28,31,30,31,30,31,31,30,31,30,31} // Get the number of days per month for a non leap year. li_DaysInMonth = li_Days[Month] // Check for a leap year. If Month = 2 Then // If the year is a leap year, change the number of days. // Leap Year Calculation: // Year divisible by 4, but not by 100, unless it is also divisible by 400 If ( (Mod(Year,4) = 0 And Mod(Year,100) <> 0) Or (Mod(Year,400) = 0) ) Then li_DaysInMonth = 29 End If End If //Return the number of days in the relevant month Return li_DaysInMonth end function public subroutine enter_day_numbers (integer ai_start_day_num, integer ai_days_in_month);Int li_count, li_daycount //Blank the columns before the first day of the month For li_count = 1 to ai_start_day_num dw_cal.SetItem(1,li_count,"") Next //Set the columns for the days to the String of their Day number For li_count = 1 to ai_days_in_month //Use li_daycount to find which column needs to be set li_daycount = ai_start_day_num + li_count - 1 dw_cal.SetItem(1,li_daycount,String(li_count)) Next //Move to next column li_daycount = li_daycount + 1 //Blank remainder of columns For li_count = li_daycount to 42 dw_cal.SetItem(1,li_count,"") Next //If there was an old column turn off the highlight unhighlight_column (is_old_column) is_old_column = '' end subroutine public function int get_month_number (string as_month);Int li_month_number CHOOSE CASE as_month CASE "Jan" li_month_number = 1 CASE "Feb" li_month_number = 2 CASE "Mar" li_month_number = 3 CASE "Apr" li_month_number = 4 CASE "May" li_month_number = 5 CASE "Jun" li_month_number = 6 CASE "Jul" li_month_number = 7 CASE "Aug" li_month_number = 8 CASE "Sep" li_month_number = 9 CASE "Oct" li_month_number = 10 CASE "Nov" li_month_number = 11 CASE "Dec" li_month_number = 12 END CHOOSE return li_month_number end function public function integer unhighlight_column (string as_column);//If the highlight is on the column set the border of the column back to normal string ls_return If as_column <> '' then ls_return = dw_cal.Modify(as_column + ".border=0") If ls_return <> "" then MessageBox("Modify",ls_return) Return -1 End if End If Return 1 end function public subroutine set_date (date ad_date); end subroutine public subroutine set_date_format (string as_date_format);// Set the format. is_DateFormat = as_date_format // Set the date with the new format. If Not isnull(id_date_selected) then set_date (id_date_selected) End If end subroutine public subroutine draw_month (integer year, integer month);Int li_FirstDayNum, li_cell, li_daysinmonth Date ld_firstday String ls_month, ls_cell, ls_return //Set Pointer to an Hourglass and turn off redrawing of Calendar SetPointer(Hourglass!) SetRedraw(dw_cal,FALSE) //Set Instance variables to arguments ii_month = month ii_year = year //check in the instance day is valid for month/year //back the day down one if invalid for month ie 31 will become 30 Do While Date(ii_year,ii_month,ii_day) = Date(00,1,1) ii_day -- Loop //Work out how many days in the month li_daysinmonth = days_in_month(ii_month,ii_year) //Find the date of the first day in the month ld_firstday = Date(ii_year,ii_month,1) //Find what day of the week this is li_FirstDayNum = DayNumber(ld_firstday) //Set the first cell li_cell = li_FirstDayNum + ii_day - 1 //If there was an old column turn off the highlight unhighlight_column (is_old_column) //Set the Title ls_Month = string(ii_Year) em_year.text = ls_month ddlb_month.text = string(ii_month,'00') //Enter the day numbers into the datawindow enter_day_numbers(li_FirstDayNum,li_daysinmonth) //Define the current cell name ls_cell = 'cell'+string(li_cell) //Highlight the current date highlight_column (ls_cell) //Set the old column for next time //is_old_column = ls_cell //Reset the pointer and Redraw SetPointer(Arrow!) dw_cal.SetRedraw(TRUE) end subroutine public subroutine init_cal (date ad_start_date);Int li_FirstDayNum, li_Cell, li_DaysInMonth String ls_Year, ls_Month, ls_Return, ls_Cell Date ld_FirstDay //Insert a row into the script datawindow dw_cal.InsertRow(0) //Set the variables for Day, Month and Year from the date passed to //the function ii_Month = Month(ad_start_date) ii_Year = Year(ad_start_date) ii_Day = Day(ad_start_date) //Find how many days in the relevant month li_daysinmonth = days_in_month(ii_month, ii_year) //Find the date of the first day of this month ld_FirstDay = Date(ii_Year, ii_month, 1) //What day of the week is the first day of the month li_FirstDayNum = DayNumber(ld_FirstDay) //Set the starting "cell" in the datawindow. i.e the column in which //the first day of the month will be displayed li_Cell = li_FirstDayNum + ii_Day - 1 //Set the Title of the calendar with the Month and Year //ls_Month = get_month_string(ii_Month) + " " + string(ii_Year) ls_Month = string(ii_Year) em_year.text = ls_month ddlb_month.text = string(ii_month,'00') //Enter the numbers of the days enter_day_numbers(li_FirstDayNum, li_DaysInMonth) dw_cal.SetItem(1,li_cell,String(Day(ad_start_date))) //Define the first Cell as a string ls_cell = 'cell'+string(li_cell) //Display the first day in bold (or 3D) highlight_column (ls_cell) //Set the instance variable i_old_column to hold the current cell, so //when we change it, we know the old setting is_old_column = ls_Cell end subroutine public function integer highlight_column (string as_column);//Highlight the current column/date int li_days li_days = integer(mid(as_column,5)) if li_days > 28 then do until isdate(em_year.text + '-' + ddlb_month.text + '-' + dw_cal.getitemstring(1,li_days)) li_days -- loop end if choose case li_days case 1 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell1.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell1.y) - 5) case 2 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell2.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell2.y) - 5) case 3 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell3.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell3.y) - 5) case 4 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell4.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell4.y) - 5) case 5 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell5.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell5.y) - 5) case 6 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell6.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell6.y) - 5) case 7 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell7.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell7.y) - 5) case 8 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell8.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell8.y) - 5) case 9 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell9.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell9.y) - 5) case 10 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell10.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell10.y) - 5) case 11 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell11.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell11.y) - 5) case 12 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell12.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell12.y) - 5) case 13 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell13.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell13.y) - 5) case 14 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell14.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell14.y) - 5) case 15 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell15.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell15.y) - 5) case 16 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell16.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell16.y) - 5) case 17 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell17.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell17.y) - 5) case 18 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell18.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell18.y) - 5) case 19 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell19.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell19.y) - 5) case 20 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell20.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell20.y) - 5) case 21 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell21.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell21.y) - 5) case 22 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell22.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell22.y) - 5) case 23 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell23.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell23.y) - 5) case 24 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell24.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell24.y) - 5) case 25 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell25.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell25.y) - 5) case 26 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell26.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell26.y) - 5) case 27 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell27.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell27.y) - 5) case 28 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell28.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell28.y) - 5) case 29 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell29.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell29.y) - 5) case 30 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell30.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell30.y) - 5) case 31 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell31.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell31.y) - 5) case 32 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell32.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell32.y) - 5) case 33 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell33.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell33.y) - 5) case 34 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell34.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell34.y) - 5) case 35 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell35.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell35.y) - 5) case 36 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell36.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell36.y) - 5) case 37 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell37.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell37.y) - 5) case 38 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell38.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell38.y) - 5) case 39 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell39.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell39.y) - 5) case 40 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell40.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell40.y) - 5) case 41 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell41.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell41.y) - 5) case 42 dw_cal.object.p_sel.x = string(long(dw_cal.object.cell42.x) - 5) dw_cal.object.p_sel.y = string(long(dw_cal.object.cell42.y) - 5) end choose ii_day = integer(dw_cal.getitemstring(1,li_days)) id_date_selected = date(ii_year, ii_month, ii_Day) is_old_column = 'cell' + string(li_days) Return 1 end function event constructor;id_date_selected = today() end event on uo_calendar_small.create this.cb_ok=create cb_ok this.cb_exit=create cb_exit this.em_year=create em_year this.pb_ok=create pb_ok this.pb_ddlb=create pb_ddlb this.dw_cal=create dw_cal this.ddlb_month=create ddlb_month this.Control[]={this.cb_ok,& this.cb_exit,& this.em_year,& this.pb_ok,& this.pb_ddlb,& this.dw_cal,& this.ddlb_month} end on on uo_calendar_small.destroy destroy(this.cb_ok) destroy(this.cb_exit) destroy(this.em_year) destroy(this.pb_ok) destroy(this.pb_ddlb) destroy(this.dw_cal) destroy(this.ddlb_month) end on type cb_ok from commandbutton within uo_calendar_small integer x = 379 integer y = 684 integer width = 233 integer height = 92 integer taborder = 60 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "确定" end type event clicked;parent.postevent('ue_close') end event type cb_exit from commandbutton within uo_calendar_small integer x = 631 integer y = 684 integer width = 233 integer height = 92 integer taborder = 50 integer textsize = -9 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "取消" end type event clicked;parent.postevent('ue_close') init_cal(today()) end event type em_year from editmask within uo_calendar_small integer x = 37 integer y = 24 integer width = 302 integer height = 84 integer taborder = 20 integer textsize = -9 integer weight = 400 fontcharset fontcharset = gb2312charset! fontpitch fontpitch = fixed! fontfamily fontfamily = modern! string facename = "新宋体" long textcolor = 16711680 borderstyle borderstyle = stylelowered! string mask = "####" boolean autoskip = true boolean spin = true double increment = 1 string minmax = "1900~~2999" end type event other;if (lparam = 33554433) and (em_year.text <> string(ii_year)) then draw_month ( integer(em_year.text), integer(ddlb_month.text) ) end if end event type pb_ok from picturebutton within uo_calendar_small integer x = 1207 integer y = 744 integer width = 91 integer height = 72 integer taborder = 40 integer textsize = -8 integer weight = 400 fontcharset fontcharset = ansi! fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "Arial" string text = "ok" boolean default = true alignment htextalign = left! vtextalign vtextalign = vcenter! end type event clicked; parent.postevent('ue_close') end event type pb_ddlb from picturebutton within uo_calendar_small integer x = 910 integer y = 744 integer width = 91 integer height = 80 integer taborder = 50 integer textsize = -8 integer weight = 400 fontpitch fontpitch = variable! fontfamily fontfamily = swiss! string facename = "MS Sans Serif" string picturename = "ddlb.bmp" alignment htextalign = left! end type event clicked; //Works as a toggle, if the DropDown is visible, make it invisible //otherwise make it visible date ld_date If dw_cal.visible then dw_cal.visible = FALSE else //Reset the datawindow reset(dw_cal) // If there is already a date in the edit box then make this the // current date in the calendar, otherwise use today If ii_day = 0 Then ii_day = 1 ld_date = date(ii_year, ii_month, ii_day) // This line used for debugging init_cal(date(ii_year, ii_month, ii_day)) dw_cal.visible = TRUE dw_cal.setfocus() End If end event type dw_cal from datawindow within uo_calendar_small event ue_dwnkey pbm_dwnkey integer width = 1385 integer height = 668 integer taborder = 10 string dataobject = "d_calendar" borderstyle borderstyle = stylelowered! end type event ue_dwnkey;long ll_cell If keydown(keyRightArrow!) and keydown(keyControl!) then if long(ddlb_month.text) >= 12 then em_year.text = string(long(em_year.text) + 1) ddlb_month.text = '1' else ddlb_month.text = string(long(ddlb_month.text) + 1) end if draw_month ( integer(em_year.text), integer(ddlb_month.text) ) return Elseif keydown(keyLeftArrow!) and keydown(keyControl!) then if long(ddlb_month.text) <= 1 then em_year.text = string(long(em_year.text) - 1) ddlb_month.text = '12' else ddlb_month.text = string(long(ddlb_month.text) - 1) end if draw_month ( integer(em_year.text), integer(ddlb_month.text) ) return elseif keydown(keyupArrow!) and keydown(keyControl!) then em_year.text = string(long(em_year.text) + 1) draw_month ( integer(em_year.text), integer(ddlb_month.text) ) return elseif keydown(keydownArrow!) and keydown(keyControl!) then em_year.text = string(long(em_year.text) - 1) draw_month ( integer(em_year.text), integer(ddlb_month.text) ) return End If if keydown(keyupArrow!) then ll_cell = long(mid(is_old_column,5)) - 7 if ll_cell > 0 then if getitemstring(1,ll_cell) <> "" then highlight_column("cell" + string(ll_cell)) ii_day = integer(getitemstring(1,ll_cell)) id_date_selected = date(ii_year, ii_month, ii_Day) end if end if end if if keydown(keydownArrow!) then ll_cell = long(mid(is_old_column,5)) + 7 if ll_cell < 42 then if getitemstring(1,ll_cell) <> "" then highlight_column("cell" + string(ll_cell)) ii_day = integer(getitemstring(1,ll_cell)) id_date_selected = date(ii_year, ii_month, ii_Day) end if end if end if if keydown(keyleftArrow!) then ll_cell = long(mid(is_old_column,5)) - 1 if ll_cell > 0 then if getitemstring(1,ll_cell) <> "" then highlight_column("cell" + string(ll_cell)) ii_day = integer(getitemstring(1,ll_cell)) id_date_selected = date(ii_year, ii_month, ii_Day) end if end if end if if keydown(keyrightArrow!) then ll_cell = long(mid(is_old_column,5)) + 1 if ll_cell < 42 then if getitemstring(1,ll_cell) <> "" then highlight_column("cell" + string(ll_cell)) ii_day = integer(getitemstring(1,ll_cell)) id_date_selected = date(ii_year, ii_month, ii_Day) end if end if end if if keydown(keyenter!) then parent.postevent('ue_close') end if end event event clicked;String ls_clickedcolumn, ls_clickedcolumnID String ls_day, ls_return string ls_col_name //Return if click was not on a valid dwobject, depending on what was //clicked, dwo will be null or dwo.name will be "datawindow" If IsNull(dwo) Then Return If Pos(dwo.name, "cell") = 0 Then Return //Find which column was clicked on and return if it is not valid ls_clickedcolumn = dwo.name ls_clickedcolumnID = dwo.id If ls_clickedcolumn = '' Then Return //Set Day to the text of the clicked column. Return if it is an empty column ls_day = dwo.primary[1] If ls_day = "" then Return //Convert to a number and place in Instance variable ii_day = Integer(ls_day) //If the highlight was on a previous column (is_old_column <> '') //set the border of the old column back to normal unhighlight_column (is_old_column) //Highlight chosen day/column dw_cal.object.p_sel.x = string(long(dwo.x) - 5) dw_cal.object.p_sel.y = string(long(dwo.y) - 5) //Set the old column for next time is_old_column = ls_clickedcolumn //Return the chosen date into the SingleLineEdit in the chosen format id_date_selected = date(ii_year, ii_month, ii_Day) ////parent.postevent('ue_close') end event event doubleclicked;String ls_day //Return if click was not on a valid dwobject, depending on what was //clicked, dwo will be null or dwo.name will be "datawindow" If IsNull(dwo) Then Return If Pos(dwo.name, "cell") = 0 Then Return //Set the Day to the chosen column ls_day = dwo.primary[1] if ls_day ='' then return //Return the chosen date into the SingleLineEdit in the chosen format ii_day = Integer(ls_day) id_date_selected = date(ii_year, ii_month, ii_Day) set_date (id_date_selected) parent.postevent('ue_close') end event type ddlb_month from dropdownlistbox within uo_calendar_small event mousemove pbm_mousemove integer x = 443 integer y = 24 integer width = 229 integer height = 704 integer taborder = 40 boolean bringtotop = true integer textsize = -9 integer weight = 400 fontcharset fontcharset = gb2312charset! fontpitch fontpitch = variable! string facename = "宋体" long textcolor = 16711680 boolean sorted = false boolean vscrollbar = true string item[] = {"01","02","03","04","05","06","07","08","09","10","11","12"} borderstyle borderstyle = stylelowered! end type event other;//If (lparam = 33554433) And (ddlb_month.Text <> String(ii_month)) THEN // draw_month ( Integer(em_year.Text), Integer(ddlb_month.Text) ) //END IF // end event event selectionchanged; //if (lparam = 33554433) and (ddlb_month.text <> string(ii_month)) then //draw_month ( integer(em_year.text), integer(ddlb_month.text) ) //end if if(ddlb_month.text <> string(ii_month)) then draw_month ( integer(em_year.text), integer(ddlb_month.text) ) end if end event