public void onSave(object sender, EventArgs e) { if (!common.validate()) { return; } var newstepList = new List <CulculateFormulaJsonModel>(); foreach (var target in editList) { var newstep = new CulculateFormulaJsonModel(); var newstepexelist = new List <ExecuteJsonModel>(); newstep.explain = target.explain.Text; if (target.final == null) { newstep.last = false; newstep.execute = newstepexelist; newstepList.Add(newstep); continue; } newstep.last = target.final.IsToggled; foreach (CulcModel cul in target.culculates) { var newexe = new ExecuteJsonModel(); string xtypeselect = SpecialUtil.typeConvertList[cul.xtypePick.Items[cul.xtypePick.SelectedIndex]]; string ytypeselect = SpecialUtil.typeConvertList[cul.ytypePick.Items[cul.ytypePick.SelectedIndex]]; newexe.culculateMethod = U.getMethodNameFromMark(cul.culcPick.Items[cul.culcPick.SelectedIndex]); newexe.xtype = xtypeselect; newexe.ytype = ytypeselect; switch (xtypeselect) { case JAN.Type_Constant_Value: newexe.xtarget = cul.xConstantEntry.Text; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: newexe.xtarget = cul.xstepPick.SelectedIndex.ToString(); break; } switch (ytypeselect) { case JAN.Type_Constant_Value: newexe.ytarget = cul.yConstantEntry.Text; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: newexe.ytarget = cul.ystepPick.SelectedIndex.ToString(); break; default: break; } newstepexelist.Add(newexe); } newstep.execute = newstepexelist; newstepList.Add(newstep); } var cj = new CulculateJsonModel(); cj.formula = newstepList; string json = Newtonsoft.Json.JsonConvert.SerializeObject(cj); UserCulculateModel um = new UserCulculateModel(); um.Culculate = json; um.Name = "Special"; um.DisplayName = common.nameEntry.Text; um.Index = 0; UserCulculateUtil.insertUserCulculate(um); mypair.refreshEditList(); mypair.DisplayAlert("確認", "新しい計算を作成しました。", "OK"); }
/// <summary> /// 計算項目作成 /// </summary> /// <returns>The culculate content.</returns> /// <param name="targetModel">更新モードの場合に指定</param> public ContentView createCulculateContent(ExecuteJsonModel targetModel, int calledIndex) { string uuid = Guid.NewGuid().ToString(); var culcModel = new CulcModel(); //ベースコンテント var returnContetnView = new ContentView { BackgroundColor = Color.FromHex("#E8E8E8") }; //ベースレイアウト var layout = new StackLayout { Style = EditorStyles.culculateContentLayoutStyle, AutomationId = uuid }; returnContetnView.Content = layout; //--- X種別ピッカーの作成 var xtypePickLayout = createTypePicker(); var xtypePick = (Picker)xtypePickLayout.Children.First(i => i is Picker); //--- Y種別ピッカーの作成 var ytypePickLayout = createTypePicker(); var ytypePick = (Picker)ytypePickLayout.Children.First(i => i is Picker); //--- 演算子ピッカーの作成 var culcPickLayout = createCalculateTypePicker(); var culcPick = (Picker)culcPickLayout.Children.First(i => i is Picker); //--- XStepピッカーの作成 var xFormulaPickLayout = createFormulaPicker(calledIndex); var xFormulaPick = (Picker)xFormulaPickLayout.Children.First(i => i is Picker); //--- YStepピッカーの作成 var yFormulaPickLayout = createFormulaPicker(calledIndex); var yFormulaPick = (Picker)yFormulaPickLayout.Children.First(i => i is Picker); //--- 計算削除ボタンの作成 var deleteCulculateButton = new Button { Text = "計算削除", Style = EditorStyles.deleteButtonStyle }; var deleteCulculateButtonLayout = new StackLayout { Style = EditorStyles.culcLayoutStyle, HorizontalOptions = LayoutOptions.Center }; deleteCulculateButtonLayout.Children.Add(deleteCulculateButton); //--- 削除ボタンのクリックイベント int deleteTarget = formulaList.Count - 1; deleteCulculateButton.Clicked += (sender, args) => { editList[deleteTarget].culculates.Remove(culcModel); ((StackLayout)returnContetnView.Parent).Children.Remove(returnContetnView); }; //--- Y定数エントリーの作成 var yConstantEntry = new Entry { Style = EditorStyles.constantEntryStyle }; var yConstantEntryLayout = new StackLayout { Style = EditorStyles.culcLayoutStyle, IsVisible = false }; var yConstantEntryLabel = new Label { Style = EditorStyles.culcLabelStyle, Text = "値 " }; yConstantEntryLayout.Children.Add(yConstantEntryLabel); yConstantEntryLayout.Children.Add(yConstantEntry); //--- Y定数エントリーのテキスト変更時のイベント yConstantEntry.TextChanged += (sender, args) => { //--- 文字数が最大値の場合はテキストを変更しない string _text = yConstantEntry.Text; if (_text.Length > V.numTextLengthMax) { _text = _text.Remove(_text.Length - 1); yConstantEntry.Text = _text; } }; //--- X定数エントリーの作成 var xConstantEntry = new Entry { Style = EditorStyles.constantEntryStyle }; var xConstantEntryLayout = new StackLayout { Style = EditorStyles.culcLayoutStyle, IsVisible = false }; var xConstantEntryLabel = new Label { Style = EditorStyles.culcLabelStyle, Text = "値 " }; xConstantEntryLayout.Children.Add(xConstantEntryLabel); xConstantEntryLayout.Children.Add(xConstantEntry); //--- X定数エントリーのテキスト変更時のイベント xConstantEntry.TextChanged += (sender, args) => { //--- 文字数が最大値の場合はテキストを変更しない string _text = xConstantEntry.Text; if (_text.Length > V.numTextLengthMax) { _text = _text.Remove(_text.Length - 1); xConstantEntry.Text = _text; } }; //--- ベースレイアウトに作成したパーツを格納 layout.Children.Add(xtypePickLayout); layout.Children.Add(xFormulaPickLayout); layout.Children.Add(xConstantEntryLayout); layout.Children.Add(culcPickLayout); layout.Children.Add(ytypePickLayout); layout.Children.Add(yFormulaPickLayout); layout.Children.Add(yConstantEntryLayout); layout.Children.Add(deleteCulculateButtonLayout); //--- 計算モデルに作成したパーツを格納 culcModel.xtypePick = xtypePick; culcModel.xstepPick = xFormulaPick; culcModel.xConstantEntry = xConstantEntry; culcModel.culcPick = culcPick; culcModel.ytypePick = ytypePick; culcModel.ystepPick = yFormulaPick; culcModel.yConstantEntry = yConstantEntry; culcModel.uuid = uuid; //--- 作成したモデルを作成リストに格納 editList.Last().culculates.Add(culcModel); //--- X種別ピッカーのインデックス変更イベント xtypePick.SelectedIndexChanged += (sender, args) => { if (layout == null) { return; } //--- 選択種別によって表示する項目を制御する switch (SpecialUtil.typeConvertList[xtypePick.Items[xtypePick.SelectedIndex]]) { case JAN.Type_Constant_Value: xConstantEntryLayout.IsVisible = true; xFormulaPickLayout.IsVisible = false; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: xConstantEntryLayout.IsVisible = false; xFormulaPickLayout.IsVisible = true; break; case JAN.Type_Previous_Culculate_Result_Value: xConstantEntryLayout.IsVisible = false; xFormulaPickLayout.IsVisible = false; break; } }; //--- Y種別ピッカーのインデックス変更イベント ytypePick.SelectedIndexChanged += (sender, args) => { if (layout == null) { return; } //--- 選択種別によって表示する項目を制御する switch (SpecialUtil.typeConvertList[ytypePick.Items[ytypePick.SelectedIndex]]) { case JAN.Type_Constant_Value: yConstantEntryLayout.IsVisible = true; yFormulaPickLayout.IsVisible = false; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: yConstantEntryLayout.IsVisible = false; yFormulaPickLayout.IsVisible = true; break; case JAN.Type_Previous_Culculate_Result_Value: yConstantEntryLayout.IsVisible = false; yFormulaPickLayout.IsVisible = false; break; } }; //--- 更新モードから呼ばれた場合は、各項目を読み込んだ状態に変更する if (targetModel != null) { xtypePick.SelectedIndex = SpecialUtil.realTypeList.IndexOf(targetModel.xtype); ytypePick.SelectedIndex = SpecialUtil.realTypeList.IndexOf(targetModel.ytype); culcPick.SelectedIndex = culcPick.Items.IndexOf(U.getMarkFromMethodName(targetModel.culculateMethod)); if (JAN.Type_Constant_Value.Equals(targetModel.xtype)) { xConstantEntry.Text = targetModel.xtarget; } if (JAN.Type_Input_Value.Equals(targetModel.xtype) || JAN.Type_Last_Culculate_Result_Value.Equals(targetModel.xtype)) { xFormulaPick.SelectedIndex = int.Parse(targetModel.xtarget); } if (JAN.Type_Constant_Value.Equals(targetModel.ytype)) { yConstantEntry.Text = targetModel.ytarget; } if (JAN.Type_Input_Value.Equals(targetModel.ytype) || JAN.Type_Last_Culculate_Result_Value.Equals(targetModel.ytype)) { yFormulaPick.SelectedIndex = int.Parse(targetModel.ytarget); } } return(returnContetnView); }
public async void onSave(object sender, EventArgs e) { var result = await mypair.DisplayAlert("確認", "計算を更新しますか?", "OK", "キャンセル"); if (!result) { return; } if (!common.validate()) { return; } var newstepList = new List <CulculateFormulaJsonModel>(); foreach (var target in editList) { var newstep = new CulculateFormulaJsonModel(); var newstepexelist = new List <ExecuteJsonModel>(); newstep.explain = target.explain.Text; if (target.final == null) { newstep.last = false; newstep.execute = newstepexelist; newstepList.Add(newstep); continue; } newstep.last = target.final.IsToggled; foreach (CulcModel cul in target.culculates) { var newexe = new ExecuteJsonModel(); string xtypeselect = SpecialUtil.typeConvertList[cul.xtypePick.Items[cul.xtypePick.SelectedIndex]]; string ytypeselect = SpecialUtil.typeConvertList[cul.ytypePick.Items[cul.ytypePick.SelectedIndex]]; newexe.culculateMethod = U.getMethodNameFromMark(cul.culcPick.Items[cul.culcPick.SelectedIndex]); newexe.xtype = xtypeselect; newexe.ytype = ytypeselect; switch (xtypeselect) { case JAN.Type_Constant_Value: newexe.xtarget = cul.xConstantEntry.Text; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: newexe.xtarget = cul.xstepPick.SelectedIndex.ToString(); break; } switch (ytypeselect) { case JAN.Type_Constant_Value: newexe.ytarget = cul.yConstantEntry.Text; break; case JAN.Type_Input_Value: case JAN.Type_Last_Culculate_Result_Value: newexe.ytarget = cul.ystepPick.SelectedIndex.ToString(); break; } newstepexelist.Add(newexe); } newstep.execute = newstepexelist; newstepList.Add(newstep); } var cj = new CulculateJsonModel(); cj.formula = newstepList; string json = JsonConvert.SerializeObject(cj); UserCulculateUtil.updateCulculateById(myUserCulculateModelTarget.Id, "Special", json, common.nameEntry.Text); mypair.refreshEditList(); await mypair.DisplayAlert("確認", "更新が完了しました", "OK"); }