【征集优秀的代码段】
idea来自最近公司内部搜集优秀的代码片段的活动。
最近江南style特火,作为开发人员的我们,长时间的coding肯定已经形成了自己独特的code style。没有标准 没有对错 没有最好 只有更好。欢迎大家来晾下自己优秀的代码片段。下面我先贴一段自己的片段,抛砖引玉~

风格差不多。
// Last Update:2012-12-01 13:50:27
/**
* @file main.cpp
* @brief
* @author xxg@jyxtec.com
* @version 0.1.00
* @date 2012-12-01
*/
#include <stdio.h>
/* --------------------------------------*/
/**
* @brief test printf "Hello World"
*/
/* --------------------------------------*/
void test(void)
{
printf("Hello World\n");
}
int
main( int argc, char **argv )
{
test();
return 0;
}

if( j == p_len-1 ) return i-p_len + 1);
//没有到最后,比较下一个位置的数据
i++,j++;
}
else{//当前比较位置不同,回溯模式串
j = next[j];
}
}
return -1;
}
int main (int argc, char *argv[]){
char s[] = "acabaabaabcacaabc";
char p[] = "abaabcac";
printf ("%d\n", kmp (s, p) - strlen (p) + 1);
return 0;
}
[解决办法]
有没有谁共献函数式语言的代码?
#pragma once
namespace std {
namespace convert_namespace {
template<typename __t1, typename __t2>
struct Convert
{
const __t1 operator () (const __t2& nValue) const
{
__t1 result_ = boost::numeric_cast<__t1>(nValue);
return result_;
}
};
template<typename __t1>
struct Convert<__t1, char *>
{
const __t1 operator () (const char * nValue) const
{
__t1 result_ = boost::lexical_cast<__t1>(nValue);
return result_;
}
};
template<typename __t1>
struct Convert<__t1, string>
{
const __t1 operator () (const string& nValue) const
{
__t1 result_ = boost::lexical_cast<__t1>(nValue);
return result_;
}
};
template<typename __t1>
struct Convert<__t1, wchar_t *>
{
const __t1 operator () (const wchar_t * nValue) const
{
__t1 result_ = boost::lexical_cast<__t1>(nValue);
return result_;
}
};
template<typename __t1>
struct Convert<__t1, wstring>
{
const __t1 operator () (const wstring& nValue) const
{
__t1 result_ = boost::lexical_cast<__t1>(nValue);
return result_;
}
};
template<>
struct Convert<bool, char *>
{
const bool operator () (const char * nValue) const
{
string value_(nValue);
boost::trim(value_);
if ("true" == value_)
{
return true;
}
return false;
}
};
template<>
struct Convert<bool, string>
{
const bool operator () (const string& nValue) const
{
string value_ = nValue;
boost::trim(value_);
if ("true" == value_)
{
return true;
}
return false;
}
};
template<>
struct Convert<bool, wchar_t *>
{
const bool operator () (const wchar_t * nValue) const
{
wstring value_(nValue);
boost::trim(value_);
if (L"true" == value_)
{
return true;
}
return false;
}
};
template<>
struct Convert<bool, wstring>
{
const bool operator () (const wstring& nValue) const
{
wstring value_(nValue);
boost::trim(value_);
if (L"true" == value_)
{
return true;
}
return false;
}
};
template<>
struct Convert<__i8, char *>
{
const __i8 operator () (const char * nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__i8 result_ = boost::numeric_cast<__i8>(result32_);
return result_;
}
};
template<>
struct Convert<__i8, string>
{
const __i8 operator () (const string& nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__i8 result_ = boost::numeric_cast<__i8>(result32_);
return result_;
}
};
template<>
struct Convert<__i8, wchar_t *>
{
const __i8 operator () (const wchar_t * nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__i8 result_ = boost::numeric_cast<__i8>(result32_);
return result_;
}
};
template<>
struct Convert<__i8, wstring>
{
const __i8 operator () (const wstring& nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__i8 result_ = boost::numeric_cast<__i8>(result32_);
return result_;
}
};
//
template<>
struct Convert<__u8, char *>
{
const __i8 operator () (const char * nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__u8 result_ = boost::numeric_cast<__u8>(result32_);
return result_;
}
};
template<>
struct Convert<__u8, string>
{
const __u8 operator () (const string& nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__u8 result_ = boost::numeric_cast<__u8>(result32_);
return result_;
}
};
template<>
struct Convert<__u8, wchar_t *>
{
const __u8 operator () (const wchar_t * nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__u8 result_ = boost::numeric_cast<__u8>(result32_);
return result_;
}
};
template<>
struct Convert<__u8, wstring>
{
const __u8 operator () (const wstring& nValue) const
{
__i32 result32_ = boost::lexical_cast<__i32>(nValue);
__u8 result_ = boost::numeric_cast<__u8>(result32_);
return result_;
}
};
template<typename __t1>
struct Convert<string, __t1>
{
const string operator () (const __t1& nValue) const
{
string result_ = boost::lexical_cast<string>(nValue);
return result_;
}
};
template<typename __t1>
struct Convert<wstring, __t1>
{
const wstring operator () (const __t1& nValue) const
{
wstring result_ = boost::lexical_cast<wstring>(nValue);
return result_;
}
};
template<>
struct Convert<string, bool>
{
const string operator () (const bool nValue) const
{
if (true == nValue)
{
return "true";
}
return "false";
}
};
template<>
struct Convert<wstring, bool>
{
const wstring operator () (const bool nValue) const
{
if (true == nValue)
{
return L"true";
}
return L"false";
}
};
template<>
struct Convert<string, wchar_t *>
{
const string operator () (const wchar_t * nValue) const
{
setlocale(LC_ALL, "");
size_t bufSize_ = 0;
size_t len_ = ::wcslen(nValue);
wcstombs_s(&bufSize_, NULL, 0, nValue, len_);
char * buf_ = new char[bufSize_];
wcstombs_s(&bufSize_, buf_, bufSize_, nValue, len_);
string result_(buf_, bufSize_);
delete[] buf_;
setlocale(LC_ALL, NULL);
return result_;
}
};
template<>
struct Convert<string, wstring>
{
const string operator () (const wstring& nValue) const
{
setlocale(LC_ALL, "");
size_t bufSize_ = 0;
const wchar_t * value_ = nValue.c_str();
size_t len_ = nValue.length();
wcstombs_s(&bufSize_, NULL, 0, value_, len_);
char * buf_ = new char[bufSize_];
wcstombs_s(&bufSize_, buf_, bufSize_, value_, len_);
string result_(buf_, bufSize_);
delete[] buf_;
setlocale(LC_ALL, NULL);
return result_;
}
};
template<>
struct Convert<wstring, char *>
{
const wstring operator () (const char * nValue) const
{
setlocale(LC_ALL, "");
size_t bufSize_ = 0;
size_t len_ = ::strlen(nValue);
mbstowcs_s(&bufSize_, NULL, 0, nValue, len_);
wchar_t * buf_ = new wchar_t[bufSize_];
mbstowcs_s(&bufSize_, buf_, bufSize_, nValue, len_);
wstring result_(buf_, bufSize_);
delete[] buf_;
setlocale(LC_ALL, NULL);
return result_;
}
};
template<>
struct Convert<wstring, string>
{
const wstring operator () (const string& nValue) const
{
setlocale(LC_ALL, "");
size_t bufSize_ = 0;
const char * value_ = nValue.c_str();
size_t len_ = nValue.length();
mbstowcs_s(&bufSize_, NULL, 0, value_, len_);
wchar_t * buf_ = new wchar_t[bufSize_];
mbstowcs_s(&bufSize_, buf_, bufSize_, value_, len_);
wstring result_(buf_, bufSize_);
delete[] buf_;
setlocale(LC_ALL, NULL);
return result_;
}
};
}
template<typename __t1, typename __t2>
const __t1 _convert(const __t2& nValue)
{
return convert_namespace::Convert<__t1, __t2>()(nValue);
}
}
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World." << std::endl;
return 0; // return with no err.
}

[解决办法]
代码无止境、思想最前行
[解决办法]
看到以下划线开头的变量或者函数就恶心。
下划线开头的变量一般都是留给编译器使用的, 那天你的变量或者函数和编译器库中的同名你就杯具了。
[解决办法]
菜鸟来围观一下!
[解决办法]
/**
* Learn from ogre.
*
* This program is just for fun or demo, in the hope that it
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2012/11/19
* File: EnnSceneNode.h
**/
#ifndef EnnSceneNode_h__
#define EnnSceneNode_h__
#include "EnnPrerequisites.h"
#include "EnnAxisAlignedBox.h"
namespace Enn
{
class SceneNode : public SceneNodeAlloc
{
public:
enum TransformSpace
{
/// Transform is relative to the local space
TS_LOCAL,
/// Transform is relative to the space of the parent node
TS_PARENT,
/// Transform is relative to world space
TS_WORLD
};
typedef map<String, MovableObject*>::type ObjectMap;
typedef ObjectMap::iterator ObjectIterator;
typedef ObjectMap::const_iterator ObjectConstIterator;
typedef map<String, SceneNode*>::type ChildMap;
typedef ChildMap::iterator ChildIterator;
typedef ChildMap::iterator ChildConstIterator;
public:
class Listener
{
public:
Listener();
virtual ~Listener();
/** Called when a node gets updated.
@remarks
Note that this happens when the node's derived update happens,
not every time a method altering it's state occurs. There may
be several state-changing calls but only one of these calls,
when the node graph is fully updated.
*/
virtual void SceneNodeUpdated(SceneNode*)
{
}
/** Node is being destroyed */
virtual void SceneNodeDestroyed(SceneNode*)
{
}
/** Node has been attached to a parent */
virtual void SceneNodeAttached(SceneNode*)
{
}
/** Node has been detached from a parent */
virtual void SceneNodeDetached(SceneNode*)
{
}
};
public:
SceneNode(const String& name, SceneManager* creator);
virtual ~SceneNode();
virtual const String& getName() const
{
return _name;
}
/** Gets this node's parent (NULL if this is the root).
*/
virtual SceneNode* getParent() const;
virtual void setParent(SceneNode* parent);
/** Returns a quaternion representing the nodes orientation.
*/
virtual const quat& getOrientation() const;
/** Sets the orientation of this node via a quaternion.
@remarks
Orientations, unlike other transforms, are not always inherited by child nodes.
Whether or not orientations affect the orientation of the child nodes depends on
the setInheritOrientation option of the child. In some cases you want a orientating
of a parent node to apply to a child node (e.g. where the child node is a part of
the same object, so you want it to be the same relative orientation based on the
parent's orientation), but not in other cases (e.g. where the child node is just
for positioning another object, you want it to maintain it's own orientation).
The default is to inherit as with other transforms.
@par
Note that rotations are oriented around the node's origin.
*/
virtual void setOrientation( const quat& q );
virtual const vec3& getPosition() const;
virtual void setPosition(const vec3& pos);
virtual const vec3& getScale() const;
virtual void setScale(const vec3& scale);
virtual void scale(const vec3& scale);
virtual void translate(const vec3& trans, TransformSpace relativeTo = TS_PARENT);
virtual void roll(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
virtual void pitch(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
virtual void yaw(const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
/** Rotate the node around an arbitrary axis.
*/
virtual void rotate(const vec3& axis, const Radian& angle, TransformSpace relativeTo = TS_LOCAL);
/** Rotate the node around an aritrary axis using a Quarternion.
*/
virtual void rotate(const quat& q, TransformSpace relativeTo = TS_LOCAL);
virtual SceneNode* createChild(
const String& name,
const vec3& trans = vec3::ZERO,
const quat& rot = quat::IDENTITY);
virtual SceneNode* createChildImpl(const String& name);
virtual void addChild(SceneNode* child);
virtual uint16 numChildren() const;
virtual SceneNode* getChild(const String& name) const;
virtual SceneNode* removeChild(const String& name);
virtual SceneNode* removeChild(SceneNode* scene_node);
virtual void removeAllChild();
virtual void updateFromParent();
virtual void updateFromParentImpl();
virtual const quat& getWorldOrientation();
virtual const vec3& getWorldScale();
virtual const vec3& getWorldPosition();
virtual const mat4& getWorldTransform();
virtual void setListener(Listener* listener);
virtual Listener* getListener() const;
virtual void setParentTransformCacheUpdated(bool dirty = true);
virtual void updateTransform();
protected:
virtual void setSelfTransformCacheDirty(bool dirty = true);
virtual void setChildTransformCacheDirty(bool dirty = true);
virtual bool isSelfTransformCacheDirty() const;
virtual bool isChildTransformCacheDirty() const;
virtual bool isParentTransformCacheDirty() const;
virtual void transformCacheDirty(bool dirty = true);
protected:
String_name;
ObjectMap_object_list;
ChildMap_child_list;
SceneManager*_creator;
AxisAlignedBox_local_aabb;
SceneNode*_parent;
quat_orientation;
vec3_position;
vec3_scale;
Listener*_listener;
quat_world_orientation;
vec3_world_scale;
vec3_world_position;
mat4_world_matrix;
bool_self_transform_cache_dirty;
bool_child_transform_cache_dirty;
bool_self_world_matrix_dirty;
bool_parent_transform_cache_dirty;
};
}
#endif /* EnnSceneNode_h__ */

cmd = new QProcess();
// movePoint = new QPoint(30, 30);
tableColumn = 6;//标记坐标表格的列数
choiceFlag = true;
mainGridLayout = new QGridLayout(this);
topHBoxLayout = new QHBoxLayout();
leftVBoxLayout = new QVBoxLayout();
rightVBoxLayout = new QVBoxLayout();
underHBoxLayout = new QHBoxLayout();
leftModel = new QStandardItemModel(this);
leftModel->setColumnCount(tableColumn);
leftModel->setHeaderData(0, Qt::Horizontal, tr("序号"));
leftModel->setHeaderData(1, Qt::Horizontal, tr("文件名"));
leftModel->setHeaderData(2, Qt::Horizontal, tr("文件路径"));
leftModel->setHeaderData(3, Qt::Horizontal, tr("类型"));
leftModel->setHeaderData(4, Qt::Horizontal, tr("状态"));
leftModel->setHeaderData(5, Qt::Horizontal, tr("加密时间"));
leftTableView = new QTableView();
leftTableView->setModel(leftModel);
//表格属性设置
leftTableView->verticalHeader()->setVisible(false);//隐藏列表头,需要#include <QHeaderView>
leftTableView->setSelectionBehavior(QAbstractItemView::SelectRows);//整行选择
leftTableView->setSelectionMode(QAbstractItemView::SingleSelection);//一次只能选择单个,防止Ctrl或者Shift进行多个选择
leftTableView->setShowGrid(true);//显示网格线
leftTableView->setEditTriggers(QTableView::NoEditTriggers);//表格禁止编辑
leftTableView->resizeColumnsToContents();//表格的列根据内容自动调整
leftTableView->resizeRowsToContents();//表格的行根据内容自动调整
leftTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);//暂时固定表格列的宽度
// leftTableView->setColumnWidth(0, 40);//初始化0列的宽度
// leftTableView->horizontalHeader()->setResizeMode(0, QHeaderView::Fixed);//固定0列的宽度
leftVBoxLayout->addWidget(leftTableView);
leftVBoxLayout->setMargin(10);
leftVBoxLayout->setSizeConstraint(QLayout::SetFixedSize);
rightTableView = new QTableView();
rightModel = new QStandardItemModel(this);
rightModel->setColumnCount(2);
rightModel->setHeaderData(0, Qt::Horizontal, tr("已加密的文件"));
rightModel->setHeaderData(1, Qt::Horizontal, tr("类型"));
rightTableView->setModel(rightModel);
rightTableView->verticalHeader()->setVisible(false);
rightTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
rightTableView->setSelectionMode(QAbstractItemView::SingleSelection);
rightTableView->setColumnWidth(0, 100);
rightTableView->setShowGrid(true);
rightTableView->setEditTriggers(QListView::NoEditTriggers);
rightTableView->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
// rightTableView->layout();
rightVBoxLayout->addWidget(rightTableView);
rightVBoxLayout->setMargin(10);
topHBoxLayout->addLayout(leftVBoxLayout);
topHBoxLayout->addLayout(rightVBoxLayout);
//setStretchFactor()设置左右控件的比例
topHBoxLayout->setStretchFactor(leftVBoxLayout, 3);
topHBoxLayout->setStretchFactor(rightVBoxLayout, 1);
clearPushButton = new QPushButton(tr("清空"));
addPushButton = new QPushButton(tr("选择文件"));
addMenu = new QMenu();
addFileAction = new QAction(QIcon("images//openfile.png"), tr("选择文件"), this);
addFolderAction = new QAction(QIcon("images//openfolder.png"), tr("选择文件夹"), this);
addMenu->addAction(addFileAction);
addMenu->addAction(addFolderAction);
addPushButton->setMenu(addMenu);//设置为下拉式
connect(addFileAction, SIGNAL(triggered()), this, SLOT(addFile()));
connect(addFolderAction, SIGNAL(triggered()), this, SLOT(addFolder()));
encryptionPushButton = new QPushButton(tr("加密"));
decryptPushButton = new QPushButton(tr("解密"));
underHBoxLayout->addWidget(clearPushButton, 1);
underHBoxLayout->addWidget(addPushButton, 1);
underHBoxLayout->addWidget(encryptionPushButton, 1);
underHBoxLayout->addWidget(decryptPushButton, 1);
underHBoxLayout->setSpacing(30);
underHBoxLayout->setAlignment(Qt::AlignRight
[解决办法]
Qt::AlignVCenter);//控件居中
mainGridLayout->addLayout(topHBoxLayout, 0, 0);
mainGridLayout->addLayout(underHBoxLayout, 1, 0);
// mainGridLayout->setColumnStretch(0, 1);
// mainGridLayout->setColumnStretch(1, 3);
mainGridLayout->setMargin(15);
//固定整个窗体的大小
this->setFixedSize(1000, 600);
encryptionFileName = 1;//标记”文件名“列
encryptionFilePath = 2;//标记“文件路径”列
fileType = 3;//标记“类型列”
encryptionStatic = 4;//标记“状态列”列
encryptionTime = 5;//标记“加密时间”列
nullIndex = leftModel->index(-1, -1);//设置行选择为空
readSettings();//构造时读取信息
// connect(addPushButton, SIGNAL(clicked()), this, SLOT(moveMenu()));
//关联相关槽
connect(clearPushButton, SIGNAL(clicked()), this, SLOT(clearData()));
connect(encryptionPushButton, SIGNAL(clicked()), this, SLOT(encryptionData()));
connect(decryptPushButton, SIGNAL(clicked()), this, SLOT(decryptData()));
connect(this, SIGNAL(stateChangeSignal(QString)), this, SLOT(stateChangeSlot(QString)));



Batch: function ()
{
if (!C.Batch.caller.Initialized)
{
var Ns = C.Slice.apply(C.Batch.caller.arguments);
if (Ns.length > 1)
{
for (var i = 0; i < Ns.length; i++)
{
C.Batch.caller.prototype.Init(C.G(Ns[i]));
}
}
else
{
C.Batch.caller.prototype.Init(C.G(Ns[0]))
}
C.Batch.caller.Initialized = true;
}
},
public ActionResult loadbook(PlanContentType type, long categoryid = 0, string keyword = "", int page = 1, int totalsize = 0, int loadtype = 1)
{
var model = new AddPlanModels();
var predicate = new List<Expression<Func<GlobalParameterInfo, bool>>>();
if (type == PlanContentType.知识学习)
{
predicate.Add(x => x.Book.BookType == BookType.课本
[解决办法]
x.Book.BookType == BookType.系统课本);
}
if (type == PlanContentType.书本阅读)
{
predicate.Add(x => x.Book.BookType == BookType.文集
[解决办法]
x.Book.BookType == BookType.辅导书);
}
if (categoryid > 0)
predicate.Add(x => x.Book.CategoryId >= categoryid && x.Book.CategoryId < categoryid.LongNext());
if (!string.IsNullOrWhiteSpace(keyword))
predicate.Add(x => x.Book.Title.Contains(keyword)
[解决办法]
x.Book.Description.Contains(keyword)
[解决办法]
x.Teacher.name.Contains(keyword));
var orderby = new Expression<Func<GlobalParameterInfo, Orderby>>[] { x => x.Book.CreateDate.Descending() };
var join = new List<Expression<Func<GlobalParameterInfo, Join>>>() { x => x.Inner(Tables.Teacher.ToString(), o => o.Book.TeacherID == o.Teacher.TeacherID) };
var field = new Expression<Func<GlobalParameterInfo, Field>>[] { x => x.Field(f => f.Book.BookId, f => f.Book.Title, f => f.Book.TitlePage, f => f.Book.OpenMethod, f => f.Book.CreateDate, f => f.Book.Status, f => f.Teacher.name.AS("Author")) };
model.Page = 1;
model.CustomPageSize = 12;
model.PlanBookList = BookManager.GetPage<PlanBookInfo>(field, join, predicate, orderby, model.Page - 1, model.PageSize);
model.TotalSize = BookManager.GetCount(x => x.Field(f => f.Book.BookId), join, predicate);
model.LoadType = loadtype;
return View("_PartialBookList", model);
}
/*
*让大家笑话了,每次面试前我都要练习这些基本功的
*Just Call Me Fish ORZ...
*/
#include <cstdio>
typedef struct Node
{
int data;
Node *next;
}Node;
Node *initList (int n)
{
Node *head, *tail;
Node *newNode = NULL;
for (int i=0; i<n; i++) {
newNode = new Node;
newNode->data = i;
if (i == 0)
head = tail = newNode;
tail->next = newNode;
tail = newNode;
tail->next = NULL;
}
return head;
}
Node *reverseList (Node *head)
{
if (head == NULL
[解决办法]
head->next == NULL)
return head;
Node *p1, *p2, *p3;
p1 = head;
p2 = p1->next;
p3 = p2->next;
p1->next = NULL;
while (p3 != NULL) {
p2->next = p1;
p1 = p2;
p2 = p3;
p3 = p3->next;
}
p2->next = p1;
head = p2;
return head;
}
Node *mergeList (Node *head1, Node *head2)//head1 & head2各自有序
{
Node *p1 = head1;
Node *p2 = head2;
if (p2 == NULL)
return p1;
if (p1 == NULL)
return p2;
Node *head, *tail;
if (p1->data > p2->data) {
head = p2;
p2 = p2->next;
}
else {
head = p1;
p1 = p1->next;
}//find head
tail = head;
while (p1 != NULL && p2 != NULL) {
if (p1->data > p2->data) {
tail->next = p2;
p2 = p2->next;
}
/*else {//保留重复的
tail->next = p1;
p1 = p1->next;
}
*/
//不保留重复的,注意选择head的时候可能重复
else if (p1->data < p2->data) {
tail->next = p1;
p1 = p1->next;
}
else {
p1 = p1->next;
continue;
}
tail = tail->next;
}
if (p1 == NULL)
tail->next = p2;
else if (p2 == NULL)
tail->next = p1;
return head;
}
void printList (Node *head)
{
for (Node *h=head; h!=NULL; h=h->next)
printf ("%d ", h->data);
printf ("\n");
return;
}
#define STRING"Hello World\n"
int main (int argc, char **argv)
{
//Node *head = initList(5);
//Node *head2 = initList(9);
//printList (head);
//printList (head2);
//head = reverseList (head);
//Node *h = mergeList(head, head2);
//printList (h);
printf (STRING);
return 0;
}
var calendarEvents = {};
function getEvents(month, year) {
var start_date = '';
if (year != undefined && month != undefined) {
start_date = year + "/";
start_date += month + "/";
start_date += '1';
}
$.ajax({
url:"/Home/BeforShowDay?date="+start_date,
type: 'POST',
dataType: 'json',
processdata: false,
contentType: 'application/json; charset=utf-8',
success: function (data) { calendarEvents = data; },
error: function (xhr, ajaxOptions, thrownError) { $("#datepicker").datepicker("hide"); },
complete: function (x, y) { $("#datepicker").datepicker("refresh"); }
});
}
$(function () {
$("#datepicker").datepicker({
beforeShowDay: function (date) {
var day = date.getDate() - 1;
if (day in calendarEvents) {
if (calendarEvents[day] == undefined) {
return [true, ''];
}
else if (calendarEvents[day].Model.train != "") {
return [true, 'td-hight-light', calendarEvents[day].Model.train];
}
}
return [false, ''];
},
onChangeMonthYear: function (year, month, inst) {
calendarEvents = {};
getEvents(month, year);
},
onSelect: function (dateText, inst) { window.location = '/LearnNet/TrainProj/TrainsByDate?date=' + dateText }
});
var calendarDate = $("#datepicker").datepicker("getDate");
getEvents(calendarDate.getMonth() + 1, calendarDate.getFullYear());