Skip to content

Commit

Permalink
源代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mthli committed Feb 25, 2014
1 parent 8a2449c commit 9f5a231
Show file tree
Hide file tree
Showing 15 changed files with 3,850 additions and 0 deletions.
123 changes: 123 additions & 0 deletions birthday_choose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "coims.h"

void birthday_choose(GtkWidget *widget, Item *parents)
{
/* dialog控件 */
GtkWidget *dialog;
GtkWidget *message;
/* 日期 */
GtkWidget *birthday_cal;
int int_year = 0,
int_month = 0,
int_day = 0;
char str[50] = {0},
str_year[10] = {0},
str_month[10] = {0},
str_day[10] = {0};
/* 时间相关 */
time_t timep;
struct tm *p;
int now_year = 0,
now_month = 0,
now_day = 0;
/* 年龄 */
int int_age = 0;
char str_age[10] = {0};
/* 临时变量 */
int i = 0,
j = 0;

/* 创建对话框 */
dialog = gtk_dialog_new_with_buttons(
"选择生日",
NULL, GTK_DIALOG_MODAL,
"确定", GTK_RESPONSE_ACCEPT,
"取消", GTK_RESPONSE_REJECT,
NULL
);
gtk_window_set_position(
GTK_WINDOW(dialog),
GTK_WIN_POS_CENTER
);
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);

/* 创建日历选择框 */
birthday_cal = gtk_calendar_new();
gtk_box_pack_start(
GTK_BOX(GTK_DIALOG(dialog) -> vbox),
birthday_cal,
TRUE,
TRUE,
0
);
/* 记住及时显示 */
gtk_widget_show(birthday_cal);

/* 处理事件 */
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
gtk_calendar_get_date(
GTK_CALENDAR(birthday_cal),
&int_year,
&int_month,
&int_day
);
int_month = int_month + 1; /* 因为获取的月份比实际月份小1 */
/* 获取当前时间 */
time(&timep);
p = gmtime(&timep);
now_year = 1900 + p -> tm_year;
now_month = 1 + p -> tm_mon;
now_day = p -> tm_mday;
/* 错误消息提示框 */
message = gtk_message_dialog_new(
NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"生日不可能超过今天"
);
if (
(int_year > now_year) ||
(int_year == now_year && int_month > now_month) ||
(int_year == now_year && int_month == now_month && int_day > now_day)
) {
gtk_widget_destroy(dialog);
gtk_dialog_run(GTK_DIALOG(message));
gtk_widget_destroy(message);
} else {
sprintf(str_year, "%d", int_year);
sprintf(str_month, "%d", int_month);
sprintf(str_day, "%d", int_day);
/* 决定采用“年月日”的显示方式,所以对字符串的处理要求高些 */
strcat(str, str_year);
strcat(str, "年");
strcat(str, str_month);
strcat(str, "月");
strcat(str, str_day);
strcat(str, "日");
gtk_button_set_label(
GTK_BUTTON((*parents).birthday_button),
str
);
int_age = now_year - int_year;
/* 如果生日的月份小于当前月份,则没过生日 */
if (int_month > now_month) {
int_age -= 1;
}
/* 如果月份相同,但日期未到,则也没过生日 */
if (int_month == now_month && int_day > now_day) {
int_age -= 1;
}
sprintf(str_age, "%d", int_age);
gtk_entry_set_text(
GTK_ENTRY((*parents).age_entry),
str_age
);
gtk_widget_show((*parents).birthday_button);
gtk_widget_show((*parents).age_entry);
gtk_widget_destroy(dialog);
}
} else {
gtk_widget_destroy(dialog);
}
}
213 changes: 213 additions & 0 deletions cancel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#include "coims.h"

void cancel(GtkWidget *widget, Item *parents)
{
/* “取消”按钮与“新建”按钮的逻辑不同,只是暂时这样做罢了:
* 1. 如果是“新建”且未保存,则“取消”按钮与新建按钮功能相同,都是清空当前界面内容
* 2. 如果是查看在院/历史病人的信息,那么“取消”按钮相当于把修改过但未保存的内容重置
*/

FILE *fp;
/* 移除照片 */
gtk_button_set_image(
GTK_BUTTON((*parents).photo_button),
NULL
);
remove("photo_path.txt");
fp = fopen("photo_path.txt", "w+");
fclose(fp);
gtk_widget_show((*parents).photo_button);
/* 移除姓名 */
gtk_entry_set_text(
GTK_ENTRY((*parents).name_entry),
""
);
gtk_widget_show((*parents).name_entry);
/* 设置“性别”下拉菜单为空 */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).sex_combo),
-1
);
gtk_widget_show((*parents).sex_combo);
/* “生日”按钮 */
gtk_button_set_label(
GTK_BUTTON((*parents).birthday_button),
"选择日期"
);
gtk_widget_show((*parents).birthday_button);
/* “年龄”输入框 */
gtk_entry_set_text(
GTK_ENTRY((*parents).age_entry),
""
);
gtk_widget_show((*parents).age_entry);
/* “婚姻” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).marriage_combo),
-1
);
gtk_widget_show((*parents).marriage_combo);
/* “教育” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).edu_combo),
-1
);
gtk_widget_show((*parents).edu_combo);
/* “身份证” */
gtk_entry_set_text(
GTK_ENTRY((*parents).id_entry),
""
);
gtk_widget_show((*parents).id_entry);
/* “户籍” */
gtk_entry_set_text(
GTK_ENTRY((*parents).census_entry),
""
);
gtk_widget_show((*parents).census_entry);
/* “发生时间” */
gtk_button_set_label(
GTK_BUTTON((*parents).happened_button),
"选择日期"
);
gtk_widget_show((*parents).happened_button);
/* “发生地点” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).place_combo),
-1
);
gtk_widget_show((*parents).place_combo);
/* “三联单” */
gtk_entry_set_text(
GTK_ENTRY((*parents).bill_entry),
""
);
gtk_widget_show((*parents).bill_entry);
/* “住院号” */
gtk_entry_set_text(
GTK_ENTRY((*parents).num_entry),
""
);
gtk_widget_show((*parents).num_entry);
/* “入院时间” */
gtk_button_set_label(
GTK_BUTTON((*parents).into_button),
"选择日期"
);
gtk_widget_show((*parents).into_button);
/* “入院评分” */
gtk_entry_set_text(
GTK_ENTRY((*parents).inps_entry),
""
);
gtk_widget_show((*parents).inps_entry);
/* “出院时间” */
gtk_button_set_label(
GTK_BUTTON((*parents).out_button),
"选择日期"
);
gtk_widget_show((*parents).out_button);
/* “出院评分” */
gtk_entry_set_text(
GTK_ENTRY((*parents).outps_entry),
""
);
gtk_widget_show((*parents).outps_entry);
/* “住院天数” */
gtk_entry_set_text(
GTK_ENTRY((*parents).days_entry),
""
);
gtk_widget_show((*parents).days_entry);
/* “减分率” */
gtk_button_set_label(
GTK_BUTTON((*parents).persent_button),
"计算"
);
gtk_widget_show((*parents).persent_button);
/* “花费” */
gtk_entry_set_text(
GTK_ENTRY((*parents).cost_entry),
""
);
gtk_widget_show((*parents).cost_entry);
/* “患者去向” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).goto_combo),
-1
);
gtk_widget_show((*parents).goto_combo);
/* “行为分级” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).level_combo),
-1
);
gtk_widget_show((*parents).level_combo);
/* “患者症状” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).symptom_combo),
-1
);
gtk_widget_show((*parents).symptom_combo);
/* “患者状态” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).status_combo),
-1
);
gtk_widget_show((*parents).status_combo);
/* “抗精神病药物” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).psy_combo),
-1
);
gtk_widget_show((*parents).psy_combo);
/* “抗抑郁药物” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).dep_combo),
-1
);
gtk_widget_show((*parents).dep_combo);
/* “抗焦虑药物” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).anxiety_combo),
-1
);
gtk_widget_show((*parents).anxiety_combo);
/* “心境稳定剂” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).heart_combo),
-1
);
gtk_widget_show((*parents).heart_combo);
/* “物质依赖” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).addicted_combo),
-1
);
gtk_widget_show((*parents).addicted_combo);
/* “是否吸毒” */
gtk_combo_box_set_active(
GTK_COMBO_BOX((*parents).drug_combo),
-1
);
gtk_widget_show((*parents).drug_combo);
/* “躯体疾病” */
gtk_entry_set_text(
GTK_ENTRY((*parents).body_entry),
""
);
gtk_widget_show((*parents).body_entry);
/* “传染病” */
gtk_entry_set_text(
GTK_ENTRY((*parents).infect_entry),
""
);
gtk_widget_show((*parents).infect_entry);
/* “确认出院” */
gtk_toggle_button_set_active(
GTK_TOGGLE_BUTTON((*parents).out_check),
FALSE
);

/* 对于clist的处理,暂时不做 */
}
Loading

0 comments on commit 9f5a231

Please sign in to comment.