Develop and Download Open Source Software

Browse Subversion Repository

Contents of /SchoolIdolFestivalSimulator.Main/MemberEditGrid.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49 - (show annotations) (download)
Thu Jul 17 15:37:46 2014 UTC (9 years, 9 months ago) by kayochin_3141
File size: 19620 byte(s)
削除追加
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using SchoolIdolFestivalSimulator.Components;
10 namespace SchoolIdolFestivalSimulator.Main {
11 public partial class MemberEditGrid : UserControl {
12 private MemberCollection _members;
13 public MemberEditGrid() {
14 InitializeComponent();
15 InitColumnSortOrder();
16 }
17 public MemberCollection Members {
18 get {
19 return _members;
20 }
21 set {
22 _members = value;
23 if (_members != null) {
24 InitComboItems();
25 LoadFromMemberCollection(_members);
26 }
27 }
28 }
29 private void LoadFromMemberCollection(MemberCollection members) {
30 foreach (Member member in members) {
31 AddMemberRow(member);
32 }
33 }
34 public void SaveMembers() {
35 _members.Clear();
36 foreach (DataGridViewRow row in grid.Rows) {
37 try {
38 if (row.IsNewRow) {
39 } else {
40 _members.Add(MemberByRow(row));
41 }
42 } catch {
43 }
44 }
45 }
46 private Member MemberByRow(DataGridViewRow row) {
47 Member member = new Member();
48 member.CardNo=Convert.ToInt32(row.Cells[(int)MemberCollection.Col.CardNo].Value);
49 member.Name=row.Cells[(int)MemberCollection.Col.Name].Value.ToString();
50 member.Rarity= ConvUtil.GetRarityFromTextJP(row.Cells[(int)MemberCollection.Col.Rarity].Value.ToString());
51 member.StatusType=ConvUtil.GetStatusTypeFromTextJP(row.Cells[(int)MemberCollection.Col.StatusType].Value.ToString());
52 member.Bonds=Convert.ToInt32(row.Cells[(int)MemberCollection.Col.Bonds].Value);
53 member.Stamina=Convert.ToInt32(row.Cells[(int)MemberCollection.Col.Stamina].Value);
54 member.StatusValue.Smile=Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.SmileValue].Value);
55 member.StatusValue.Pure = Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.PureValue].Value);
56 member.StatusValue.Cool = Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.CoolValue].Value);
57 member.Skill.Name=row.Cells[(int)MemberCollection.Col.SkillName].Value.ToString();
58 member.Skill.Level=Convert.ToInt32(row.Cells[(int)MemberCollection.Col.SkillLevel].Value.ToString());
59 member.Skill.RaiseType= ConvUtil.GetRaiseTypeFromTextJP(row.Cells[(int)MemberCollection.Col.SkillRaiseType].Value.ToString());
60 member.Skill.RaiseCount=Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.SkillRaiseCount].Value.ToString());
61 member.Skill.Ratio=Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.SkillRatio].Value.ToString()) / 100.0m;
62 member.Skill.UpType= ConvUtil.GetSkillUpTypeFromTextJP(row.Cells[(int)MemberCollection.Col.SkillUpType].Value.ToString());
63 member.Skill.UpValue = Convert.ToDecimal(row.Cells[(int)MemberCollection.Col.SkillUpValue].Value.ToString());
64 member.CenterSkill = ConvUtil.GetCenterSkillFromTextJP(row.Cells[(int)MemberCollection.Col.CenterSkill].Value.ToString());
65 return member;
66 }
67
68 private void AddMemberRow(Member member) {
69 DataGridViewRow row = new DataGridViewRow();
70 row.CreateCells(grid);
71 row.Cells[(int)MemberCollection.Col.CardNo].Value = member.CardNo;
72 row.Cells[(int)MemberCollection.Col.Name].Value = member.Name;
73 row.Cells[(int)MemberCollection.Col.Rarity].Value = ConvUtil.GetRarityTextJP(member.Rarity);
74 row.Cells[(int)MemberCollection.Col.StatusType].Value = ConvUtil.GetStatusTypeTextJP(member.StatusType);
75 row.Cells[(int)MemberCollection.Col.Bonds].Value = member.Bonds;
76 row.Cells[(int)MemberCollection.Col.Stamina].Value = member.Stamina;
77 row.Cells[(int)MemberCollection.Col.SmileValue].Value = member.StatusValue.Smile;
78 row.Cells[(int)MemberCollection.Col.PureValue].Value = member.StatusValue.Pure;
79 row.Cells[(int)MemberCollection.Col.CoolValue].Value = member.StatusValue.Cool;
80 row.Cells[(int)MemberCollection.Col.SkillName].Value = member.Skill.Name;
81 row.Cells[(int)MemberCollection.Col.SkillLevel].Value = member.Skill.Level;
82 row.Cells[(int)MemberCollection.Col.SkillRaiseType].Value = ConvUtil.GetRaiseTypeTextJP(member.Skill.RaiseType);
83 row.Cells[(int)MemberCollection.Col.SkillRaiseCount].Value = member.Skill.RaiseCount;
84 row.Cells[(int)MemberCollection.Col.SkillRatio].Value = System.Math.Floor(member.Skill.Ratio * 100.0m);
85 row.Cells[(int)MemberCollection.Col.SkillUpType].Value = ConvUtil.GetSkillUpTypeTextJP(member.Skill.UpType);
86 row.Cells[(int)MemberCollection.Col.SkillUpValue].Value = member.Skill.UpValue;
87 row.Cells[(int)MemberCollection.Col.CenterSkill].Value = member.CenterSkill.CenterSkillName;
88 grid.Rows.Add(row);
89 }
90 private void InitComboItems() {
91 SetNameComboItem();
92 SetCenterSkillComboItem();
93 SetSkillUpTypeComboItem();
94 SetSkillRaiseTypeComboItem();
95 SetStatusTypeComboItem();
96 SetRarityComboItem();
97 }
98 private void SetNameComboItem() {
99 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.Name)];
100 col.Items.Clear();
101 for (int i = 0; i <= 8; i++) {
102 col.Items.Add(ConvUtil.NameFromIndex(i));
103 }
104 }
105 private void SetRarityComboItem() {
106 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.Rarity)];
107 col.Items.Clear();
108 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.N));
109 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.AwakenN));
110 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.R));
111 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.AwakenR));
112 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.SR));
113 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.AwakenSR));
114 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.UR));
115 col.Items.Add(ConvUtil.GetRarityTextJP(Rarity.AwakenUR));
116 }
117 private void SetStatusTypeComboItem() {
118 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.StatusType)];
119 col.Items.Clear();
120 col.Items.Add(ConvUtil.GetStatusTypeTextJP(StatusType.Smile));
121 col.Items.Add(ConvUtil.GetStatusTypeTextJP(StatusType.Pure));
122 col.Items.Add(ConvUtil.GetStatusTypeTextJP(StatusType.Cool));
123 }
124 private void SetSkillRaiseTypeComboItem() {
125 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.SkillRaiseType)];
126 col.Items.Clear();
127 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.None));
128 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.Seconds));
129 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.IconCount));
130 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.Combo));
131 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.Perfect));
132 col.Items.Add(ConvUtil.GetRaiseTypeTextJP(SkillRaiseType.Score));
133 }
134 private void SetSkillUpTypeComboItem() {
135 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.SkillUpType)];
136 col.Items.Clear();
137 col.Items.Add(ConvUtil.GetSkillUpTypeTextJP(SkillUpType.None));
138 col.Items.Add(ConvUtil.GetSkillUpTypeTextJP(SkillUpType.Score));
139 col.Items.Add(ConvUtil.GetSkillUpTypeTextJP(SkillUpType.Decision));
140 col.Items.Add(ConvUtil.GetSkillUpTypeTextJP(SkillUpType.Stamina));
141 }
142 private void SetCenterSkillComboItem() {
143 DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)grid.Columns[Convert.ToInt32(MemberCollection.Col.CenterSkill)];
144 col.Items.Clear();
145 col.Items.Add((new CenterSkill(StatusType.Smile, StatusType.Smile, 0.03m).CenterSkillName));
146 col.Items.Add((new CenterSkill(StatusType.Pure, StatusType.Pure, 0.03m).CenterSkillName));
147 col.Items.Add((new CenterSkill(StatusType.Cool, StatusType.Cool, 0.03m).CenterSkillName));
148 col.Items.Add((new CenterSkill(StatusType.Smile, StatusType.Smile, 0.06m).CenterSkillName));
149 col.Items.Add((new CenterSkill(StatusType.Pure, StatusType.Pure, 0.06m).CenterSkillName));
150 col.Items.Add((new CenterSkill(StatusType.Cool, StatusType.Cool, 0.06m).CenterSkillName));
151 col.Items.Add((new CenterSkill(StatusType.Smile, StatusType.Smile, 0.09m).CenterSkillName));
152 col.Items.Add((new CenterSkill(StatusType.Pure, StatusType.Pure, 0.09m).CenterSkillName));
153 col.Items.Add((new CenterSkill(StatusType.Cool, StatusType.Cool, 0.09m).CenterSkillName));
154 col.Items.Add((new CenterSkill(StatusType.Pure, StatusType.Smile, 0.12m).CenterSkillName));
155 col.Items.Add((new CenterSkill(StatusType.Cool, StatusType.Smile, 0.12m).CenterSkillName));
156 col.Items.Add((new CenterSkill(StatusType.Smile, StatusType.Pure, 0.12m).CenterSkillName));
157 col.Items.Add((new CenterSkill(StatusType.Cool, StatusType.Pure, 0.12m).CenterSkillName));
158 col.Items.Add((new CenterSkill(StatusType.Smile, StatusType.Cool, 0.12m).CenterSkillName));
159 col.Items.Add((new CenterSkill(StatusType.Pure, StatusType.Cool, 0.12m).CenterSkillName));
160 }
161
162 private void grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) {
163 switch (grid.CurrentCell.ColumnIndex) {
164 case (int)MemberCollection.Col.Bonds:
165 case (int)MemberCollection.Col.CardNo:
166 case (int)MemberCollection.Col.Stamina:
167 case (int)MemberCollection.Col.SmileValue:
168 case (int)MemberCollection.Col.PureValue:
169 case (int)MemberCollection.Col.CoolValue:
170 case (int)MemberCollection.Col.SkillLevel:
171 DataGridViewTextBoxEditingControl tc = (DataGridViewTextBoxEditingControl)e.Control;
172 tc.KeyPress += IntTextBox_KeyPress;
173 break;
174 case (int)MemberCollection.Col.SkillRaiseCount:
175 case (int)MemberCollection.Col.SkillRatio:
176 case (int)MemberCollection.Col.SkillUpValue:
177 tc = (DataGridViewTextBoxEditingControl)e.Control;
178 tc.KeyPress += DecimalTextBox_KeyPress;
179 break;
180 }
181 }
182 private void IntTextBox_KeyPress(object sender, KeyPressEventArgs e) {
183 if(e.KeyChar == '\b'){
184 e.Handled = false;
185 return;
186 }
187 if (char.IsDigit(e.KeyChar)) {
188 e.Handled = false;
189 return;
190 }
191 e.Handled = true;
192 }
193 private void DecimalTextBox_KeyPress(object sender, KeyPressEventArgs e) {
194 if (e.KeyChar == '\b') {
195 e.Handled = false;
196 return;
197 }
198 if (char.IsDigit(e.KeyChar)) {
199 e.Handled = false;
200 return;
201 }
202 if (e.KeyChar == '.') {
203 TextBox target = sender as TextBox;
204 if (target.Text.IndexOf('.') < 0 && target.Text.Length > 0) {
205 e.Handled = false;
206 return;
207 }
208 }
209 e.Handled = true;
210 }
211 private void InitColumnSortOrder() {
212 foreach (DataGridViewColumn col in grid.Columns) {
213 col.Tag = SortOrder.Descending;
214 }
215 }
216 private SortOrder GetNextSortOrder(DataGridViewColumn col) {
217 SortOrder so = (SortOrder)col.Tag;
218 if (so == SortOrder.Descending) {
219 return SortOrder.Ascending;
220 } else if (so == SortOrder.Ascending) {
221 return SortOrder.Descending;
222 } else {
223 return SortOrder.Ascending;
224 }
225 }
226 private void SetSortOrder(DataGridViewColumn col,SortOrder so) {
227 col.Tag = so;
228 }
229 private void grid_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
230 SortOrder so = GetNextSortOrder(grid.Columns[e.ColumnIndex]);
231 switch (e.ColumnIndex) {
232 case (int)MemberCollection.Col.CenterSkill:
233 grid.Sort(new CenterSkillComparer(so));
234 break;
235 case (int)MemberCollection.Col.Name:
236 grid.Sort(new MemberNameComparer(so));
237 break;
238 case (int)MemberCollection.Col.Rarity:
239 grid.Sort(new RarityComparer(so));
240 break;
241 case (int)MemberCollection.Col.SkillRaiseType:
242 grid.Sort(new SkillRaiseTypeComparer(so));
243 break;
244 case (int)MemberCollection.Col.SkillUpType:
245 grid.Sort(new SkillUpTypeComparer(so));
246 break;
247 case (int)MemberCollection.Col.StatusType:
248 grid.Sort(new StatusTypeComparer(so));
249 break;
250 }
251 grid.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = so;
252 SetSortOrder(grid.Columns[e.ColumnIndex], so);
253 }
254 private void ShowSearchedMember(SearchedMember member, ShowSearchedMemberType type,int rowIndex) {
255 DataGridViewRow row = grid.Rows[rowIndex];
256 row.Cells[(int)MemberCollection.Col.Name].Value = member.Name;
257 row.Cells[(int)MemberCollection.Col.Rarity].Value = ConvUtil.GetRarityTextJP(member.GetRarity(type));
258 row.Cells[(int)MemberCollection.Col.StatusType].Value = ConvUtil.GetStatusTypeTextJP(member.StatusType);
259 row.Cells[(int)MemberCollection.Col.Bonds].Value = member.Bonds(type);
260 row.Cells[(int)MemberCollection.Col.Stamina].Value = member.Stamina(type);
261 row.Cells[(int)MemberCollection.Col.SmileValue].Value = member.SmileValue(type);
262 row.Cells[(int)MemberCollection.Col.PureValue].Value = member.PureValue(type);
263 row.Cells[(int)MemberCollection.Col.CoolValue].Value = member.CoolValue(type);
264 row.Cells[(int)MemberCollection.Col.SkillName].Value = member.Skill.Name;
265 row.Cells[(int)MemberCollection.Col.SkillLevel].Value = member.Skill.Level;
266 row.Cells[(int)MemberCollection.Col.SkillRaiseType].Value = ConvUtil.GetRaiseTypeTextJP(member.Skill.RaiseType);
267 row.Cells[(int)MemberCollection.Col.SkillRaiseCount].Value = member.Skill.RaiseCount;
268 row.Cells[(int)MemberCollection.Col.SkillRatio].Value = System.Math.Floor(member.Skill.Ratio * 100.0m);
269 row.Cells[(int)MemberCollection.Col.SkillUpType].Value = ConvUtil.GetSkillUpTypeTextJP(member.Skill.UpType);
270 row.Cells[(int)MemberCollection.Col.SkillUpValue].Value = member.Skill.UpValue;
271 row.Cells[(int)MemberCollection.Col.CenterSkill].Value = member.CenterSkill.CenterSkillName;
272 }
273 private SearchedMember SearchedMemberByRow(int rowIndex) {
274 object tag=grid.Rows[rowIndex].Tag;
275 if (tag == null) {
276 return null;
277 }
278 if (tag.GetType() != typeof(SearchedMember)) {
279 return null;
280 }
281 return (SearchedMember)tag;
282 }
283 private void grid_CellValidated(object sender, DataGridViewCellEventArgs e) {
284 if (e.ColumnIndex != (int)MemberCollection.Col.CardNo) {
285 return;
286 }
287 object gridValue = grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
288 if (gridValue == null) {
289 grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "0";
290 return;
291 }
292 if (gridValue.ToString() == "0") {
293 return;
294 }
295 if (this.SearchedMemberByRow(e.RowIndex) != null && this.SearchedMemberByRow(e.RowIndex).CardId.ToString() == gridValue.ToString()) {
296 return;
297 }
298 if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable()) {
299 return;
300 }
301 Cursor.Current = Cursors.WaitCursor;
302 try {
303 SearchedMember member = new SearchedMember(Convert.ToInt32(gridValue.ToString()));
304 if (member.Name == null) {
305 throw new ApplicationException("指定されたNoのメンバーは登録されていません");
306 }
307 grid.Rows[e.RowIndex].Tag = member;
308 ShowSearchedMember(member,ShowSearchedMemberType.Lv1,e.RowIndex);
309 } catch (EDownloadFailedException) {
310 grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
311 } catch (Exception ex) {
312 MessageBox.Show(this, ex.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
313 grid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0;
314 } finally {
315 Cursor.Current = Cursors.Default;
316 }
317
318 }
319 private void grid_CellEnter(object sender, DataGridViewCellEventArgs e) {
320 }
321
322 private void mnuNotAwakenLv1_Click(object sender, EventArgs e) {
323 ShowSearchedMember(SearchedMemberByRow(grid.CurrentCell.RowIndex), ShowSearchedMemberType.Lv1,grid.CurrentCell.RowIndex);
324 }
325
326 private void mnuNotAwakenLvMax_Click(object sender, EventArgs e) {
327 ShowSearchedMember(SearchedMemberByRow(grid.CurrentCell.RowIndex), ShowSearchedMemberType.Max, grid.CurrentCell.RowIndex);
328 }
329
330 private void mnuAwakenLvMax_Click(object sender, EventArgs e) {
331 ShowSearchedMember(SearchedMemberByRow(grid.CurrentCell.RowIndex), ShowSearchedMemberType.AwakenMax, grid.CurrentCell.RowIndex);
332 }
333
334 private void contextMenuStrip1_Opened(object sender, EventArgs e) {
335 SearchedMember member = SearchedMemberByRow(grid.CurrentCell.RowIndex);
336 mnuNotAwakenLv1.Enabled = member != null;
337 mnuNotAwakenLvMax.Enabled = member != null;
338 mnuAwakenLvMax.Enabled = member != null;
339 }
340
341 private void mnuDelete_Click(object sender, EventArgs e) {
342 if (grid.Rows[grid.CurrentCell.RowIndex].IsNewRow) {
343 return;
344 }
345 grid.Rows.RemoveAt(grid.CurrentCell.RowIndex);
346 }
347 }
348 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26