コード例 #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (DataController.StartedActivity.ContainsKey(ACTIVITY_NAME) && DataController.StartedActivity[ACTIVITY_NAME])
            {
                this.Finish();
                return;
            }
            DataController.StartedActivity[ACTIVITY_NAME] = true;

            SetContentView(Resource.Layout.activity_create_class);
            SupportActionBar.Hide();

            week = Intent.GetIntExtra("Week", 0);

            if (Intent.GetBooleanExtra("Edit", false))
            {
                begHour    = Intent.GetIntExtra("CurBeginHour", 0);
                begMinute  = Intent.GetIntExtra("CurBeginMinute", 0);
                endHour    = Intent.GetIntExtra("CurEndHour", 0);
                endMinute  = Intent.GetIntExtra("CurEndMinute", 0);
                chgUUID    = Intent.GetStringExtra("CurUUID");
                chgSubject = Intent.GetStringExtra("CurSubject");
                FindViewById <TextView>(Resource.Id.BeginTimeText).Text    = FmtInt(begHour) + " : " + FmtInt(begMinute);
                FindViewById <TextView>(Resource.Id.EndTimeText).Text      = FmtInt(endHour) + " : " + FmtInt(endMinute);
                FindViewById <Button>(Resource.Id.CreateClassButton).Text  = "修改";
                FindViewById <TextView>(Resource.Id.AddClassTextView).Text = "修改课程";
            }

            FindViewById <TextView>(Resource.Id.SubjectNameText).Text = chgSubject;

            string[] hours = new string[24], minutes = new string[60];
            for (int i = 0; i != 60; ++i)
            {
                minutes[i] = FmtInt(i) + "分";
            }
            for (int i = 0; i != 24; ++i)
            {
                hours[i] = FmtInt(i) + "时";
            }


            FindViewById <TextView>(Resource.Id.SwitchBeginTimeButton).Click +=
                (sender, e) =>
            {
                var intent = new Intent(this, typeof(PickTimeActivity));
                intent.PutExtra("Title", "开始时间");
                intent.PutExtra("Minutes", GetDisplayTime(begHour) * 60 + GetDisplayTime(begMinute));
                StartActivityForResult(intent, 4);
            };
            FindViewById <TextView>(Resource.Id.SwitchEndTimeButton).Click +=
                (sender, e) =>
            {
                var intent = new Intent(this, typeof(PickTimeActivity));
                intent.PutExtra("Title", "结束时间");
                intent.PutExtra("Minutes", GetDisplayTime(endHour) * 60 + GetDisplayTime(endMinute));
                StartActivityForResult(intent, 5);
            };

            FindViewById <Button>(Resource.Id.SwitchSubjectButton).Click += (sender, e) =>
            {
                var intent = new Intent(this, typeof(EditSubjectActivity));
                intent.PutExtra("Select", true);
                StartActivityForResult(intent, 444); // 米4达
            };
            FindViewById <Button>(Resource.Id.CancelCreateClassButton).Click +=
                (sender, e) =>
            {
                this.Finish();
            };
            FindViewById <Button>(Resource.Id.CreateClassButton).Click +=
                (sender, e) =>
            {
                ClassTime ct = new ClassTime();
                ct.ClassName = chgSubject;
                if (ct.ClassName == "未选择")
                {
                    Toast.MakeText(this, "请选择科目!", ToastLength.Short).Show();
                    return;
                }
                if (begHour == -1 || begMinute == -1)
                {
                    Toast.MakeText(this, "请选择课程开始时间!", ToastLength.Short).Show();
                    return;
                }
                if (endHour == -1 || endMinute == -1)
                {
                    Toast.MakeText(this, "请选择课程结束时间!", ToastLength.Short).Show();
                    return;
                }
                if (begHour * 60 + begMinute >= endHour * 60 + endMinute)
                {
                    Toast.MakeText(this, "课程结束时间必须晚于课程开始时间!", ToastLength.Short).Show();
                    return;
                }
                if (Intent.GetBooleanExtra("Edit", false))
                {
                    DataController.RemoveClass(week, chgUUID);
                }
                ct.BeginHour   = begHour;
                ct.BeginMinute = begMinute;
                ct.EndHour     = endHour;
                ct.EndMinute   = endMinute;
                try
                {
                    DataController.AddClass(week, ct);
                }
                catch (System.Exception ee)
                {
                    Toast.MakeText(this, ee.Message, ToastLength.Long).Show();
                    return;
                }
                Toast.MakeText(this, "课程添加成功!", ToastLength.Short);
                this.SetResult(Result.Ok);
                this.Finish();
                return;
            };

            // Create your application here
        }
コード例 #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (DataController.StartedActivity.ContainsKey(ACTIVITY_NAME) && DataController.StartedActivity[ACTIVITY_NAME])
            {
                this.Finish();
                return;
            }
            DataController.StartedActivity[ACTIVITY_NAME] = true;

            SetContentView(Resource.Layout.activity_create_subject);
            color = "Unknown";

            FindViewById <EditText>(Resource.Id.ViewSubjectName).Visibility  = ViewStates.Gone;
            FindViewById <EditText>(Resource.Id.InputSubjectName).Visibility = ViewStates.Visible;
            if (Intent.GetBooleanExtra("Edit", false))
            {
                FindViewById <ImageView>(Resource.Id.NewSubjectImage).SetImageResource(
                    DataController.GetClassImage(Intent.GetStringExtra("Name"), out color));
                //FindViewById<EditText>(Resource.Id.ViewSubjectName).Text = Intent.GetStringExtra("Name");
                FindViewById <EditText>(Resource.Id.InputSubjectName).Text = Intent.GetStringExtra("Name");
                //FindViewById<EditText>(Resource.Id.ViewSubjectName).Visibility = ViewStates.Visible;
                //FindViewById<EditText>(Resource.Id.InputSubjectName).Visibility = ViewStates.Gone;
                string dispColor;
                switch (color)
                {
                case "Chinese":
                    dispColor = "橙色";
                    break;

                case "Math":
                    dispColor = "蓝色";
                    break;

                case "English":
                    dispColor = "绿色";
                    break;

                case "PE":
                    dispColor = "红色";
                    break;

                case "Art":
                    dispColor = "紫色";
                    break;

                case "Music":
                    dispColor = "青色";
                    break;

                default:
                    dispColor = "默认灰";
                    break;
                }
                FindViewById <TextView>(Resource.Id.NewSubjectColor).Text     = dispColor;
                FindViewById <Button>(Resource.Id.CreateSubjectButton).Text   = "修改";
                FindViewById <TextView>(Resource.Id.AddSubjectTextView).Text  = "编辑科目";
                FindViewById <EditText>(Resource.Id.InputSubjectName).Enabled = true;
                beforeChange = Intent.GetStringExtra("Name");
            }

            FindViewById <Button>(Resource.Id.PickColorButton).Click += (sender, e) =>
            {
                StartActivityForResult(new Intent(this, typeof(PickColorActivity)), 9810);
            };
            FindViewById <Button>(Resource.Id.CancelCreateSubjectButton).Click += (sender, e) =>
            {
                this.SetResult(Result.Canceled);
                this.Finish();
                return;
            };
            FindViewById <Button>(Resource.Id.CreateSubjectButton).Click += (sender, e) =>
            {
                dispName = FindViewById <EditText>(Resource.Id.InputSubjectName).Text;
                if (dispName == "*#1919810114514#*") // TEST CODE
                {
                    Toast.MakeText(this, "进入压力测试", ToastLength.Short).Show();
                    DataController.GenerateTestData();
                    Toast.MakeText(this, "测试数据生成完成, 请返回到主界面", ToastLength.Short).Show();
                    this.Finish();
                    return;
                }
                if (dispName.Length > 5)
                {
                    Toast.MakeText(this, "科目名称太长了, 换一个吧!", ToastLength.Long).Show();
                    return;
                }
                if (dispName.Trim().Length == 0)
                {
                    Toast.MakeText(this, "请输入科目名称!", ToastLength.Long).Show();
                    return;
                }
                if (dispName.Contains(' '))
                {
                    Toast.MakeText(this, "科目名称不允许含有空格!", ToastLength.Long).Show();
                    return;
                }
                if (dispName == "未选择" || dispName == "新建科目")
                {
                    Toast.MakeText(this, "此名称不允许使用!", ToastLength.Long).Show();
                    return;
                }

                if (Intent.GetBooleanExtra("Edit", false))
                {
                    DataController.ModifySubjectColor(dispName, color);
                    if (beforeChange != dispName)
                    {
                        var subjects = DataController.GetSubjects();
                        if (subjects.Contains(dispName))
                        {
                            Toast.MakeText(this, "科目重复了!", ToastLength.Long).Show();
                            return;
                        }
                        DataController.ModifySubjectName(beforeChange, dispName);
                        try
                        {
                            DataController.AddSubject(beforeChange, dispName);
                        } catch (System.Exception ee)
                        {
                            Toast.MakeText(this, ee.Message, ToastLength.Long).Show();
                            return;
                        }
                    }
                    Toast.MakeText(this, "修改成功!", ToastLength.Short).Show();
                }
                else
                {
                    var subjects = DataController.GetSubjects();
                    if (subjects.Contains(dispName))
                    {
                        Toast.MakeText(this, "科目重复了!", ToastLength.Long).Show();
                        return;
                    }

                    DataController.CreatedSubjectName = dispName;
                    try
                    {
                        DataController.AddSubject(dispName, color);
                    } catch (System.Exception ee)
                    {
                        Toast.MakeText(this, ee.Message, ToastLength.Long).Show();
                        return;
                    }
                    Toast.MakeText(this, "添加成功!", ToastLength.Short).Show();
                }
                this.SetResult(Result.Ok);
                this.Finish();
                return;
            };
            // Create your application here
        }
コード例 #3
0
 void DeleteClass(object sender, object e)
 {
     DataController.RemoveClass(week, UUID);
     this.Finish();
 }