void V_Data_E_CellClicked(object sender, FormAdders.EasyGridViewCollections.CellClickEventArgs e) { if (e.RowIndex < 0 || e.ColIndex < 0) { return; } String packetName = (V_Data.GetCell(e.RowIndex, 1).Value as String); if (e.ColIndex == (int)Titles.edit_button) //edit msg { CPacketStruct cp = V_Data.RowRelativeObject(e.RowIndex)["parser"] as CPacketStruct; cp.MakeMsgText(); //cp.MakeMsg(); String msgFile = _packetDir + "\\" + packetName + "\\Msg.txt"; DlgMsgMaker msgMaker = new DlgMsgMaker(cp, msgFile, _endian == Endians.Big); msgMaker.Location = this.Location; msgMaker.ShowDialog(); cp.MakePacket(_endian == Endians.Big); //cp.MakeMsg();//다시 메시지를 만들어준다. } else if (e.ColIndex == (int)Titles.send) //send msg { CPacketStruct cp = V_Data.RowRelativeObject(e.RowIndex)["parser"] as CPacketStruct; cp.MakePacket(_endian == Endians.Big); _sendFunc(cp.PacketBuffer, 0, cp.PacketDataSize, cp); ReleaseSelections(); V_Data.Rows[e.RowIndex].RowBackMode = FormAdders.EasyGridViewCollections.RowBackModes.Red; } else//내용보기 { V_Contents.RelativeObject["name"] = packetName; CPacketStruct cp = V_Data.RowRelativeObject(e.RowIndex)["parser"] as CPacketStruct; viewContent(cp); } }
void V_Contents_E_TextChanged(object sender, CellTextChangedEventArgs e) { int itemIndex = (int)V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.itemIndex.ToString()]; int valueIndex = (int)V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.valueIndex.ToString()]; CPacketStruct parser = V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.parser.ToString()] as CPacketStruct; switch ((contentTitles)e.ColIndex) { case contentTitles.name: if (e.Text.Length == 0) //아무것도 넣지않으면 자동으로 복귀 { e.IsCancel = true; return; } else if (Char.IsDigit(e.Text[0])) { MessageBox.Show("변수명의 처음은 문자로 시작해야 합니다."); e.IsCancel = true; return; } else { for (int i = 0; i < e.Text.Length; i++) { if (Char.IsLetterOrDigit(e.Text, i) == false) { MessageBox.Show("변수명에는 문자와 숫자만 들어갈 수 있습니다."); e.IsCancel = true; return; } } for (int i = 0; i < parser.Items.Count; i++) { if (parser.Items[i].Name.Equals(e.Text)) { MessageBox.Show("같은 이름이 존재합니다."); e.IsCancel = true; return; } } } parser.Items[itemIndex].Name = e.Text; if (parser.Items[itemIndex].InitValues.Length > 1) //배열일 때, { viewContent(parser); //목록을 다시 만듬. } break; case contentTitles.value: parser.Items[itemIndex].InitValues[valueIndex] = e.Text; break; } parser.MakePacket(_endian == Endians.Big); parser.MakeMsgText(); String name = V_Contents.RelativeObject["name"] as String; _modifiedItems[name] = parser; }
void V_Contents_E_ComboBoxChanged(object sender, CellComboBoxEventArgs e) { int itemIndex = (int)V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.itemIndex.ToString()]; int valueIndex = (int)V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.valueIndex.ToString()]; CPacketStruct parser = V_Contents.Rows[e.RowIndex].RelativeObject[rowInfos.parser.ToString()] as CPacketStruct; switch ((contentTitles)e.ColIndex) { case contentTitles.swap: parser.Items[itemIndex].IsSwap = (_swapYn[e.SelectedIndex].Equals("y")); break; case contentTitles.type: //parser.Items[itemIndex].TypeString = _types[e.SelectedIndex]; parser.Items[itemIndex].SetType(_types[e.SelectedIndex], true); break; } try { parser.MakePacket(_endian == Endians.Big); parser.MakeMsgText(); String name = V_Contents.RelativeObject["name"] as String; _modifiedItems[name] = parser; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void SaveFile() { //File.WriteAllText(_saveFile, T_Msg.Text); _ns.NativeText = T_Msg.Text;//.setNativeText(ss); //_ns.Items = StructXMLParser.CodeToItems(T_Msg.Text, _ns); if (_ns.IsDynamicPacket == false) { _ns.MakePacket(_swapWhenMakePacket); } CStructInfo info = new CStructInfo(T_Comment.Text, DateTime.Now); StructXMLParser.ItemsToXml(_ns.Items, _xmlFile, info); }
private void B_Save_Click(object sender, EventArgs e) { try { _ns.MakePacket(T_Struct.Text, _swapWhenMakePacket); } catch (Exception ex) { MessageBox.Show("문법에 오류가 있습니다 : " + ex.Message); return; } StreamWriter file = File.CreateText(_saveFile); file.Write(T_Struct.Text); file.Close(); Close(); }
void V_Data_E_CellClicked(object sender, FormAdders.EasyGridViewCollections.CellClickEventArgs e) { if (e.ColIndex == (int)Titles.edit_button) //edit msg { CPacketStruct cp = V_Data.RowRelativeObject(e.RowIndex)["parser"] as CPacketStruct; cp.MakeMsgText(); String msgFile = _packetDir + "\\" + (V_Data.GetCell(e.RowIndex, 1).Value as String) + "\\Msg.txt"; DlgMsgMaker msgMaker = new DlgMsgMaker(cp, msgFile, _endian == Endians.Big); msgMaker.Location = this.Location; msgMaker.ShowDialog(); } else if (e.ColIndex == (int)Titles.send) //send msg { CPacketStruct cp = V_Data.RowRelativeObject(e.RowIndex)["parser"] as CPacketStruct; cp.MakePacket(_endian == Endians.Big); _sendFunc(cp.PacketBuffer, 0, cp.PacketDataSize, cp.SimpleText); ReleaseSelections(); V_Data.Rows[e.RowIndex].RowBackMode = FormAdders.EasyGridViewCollections.RowBackModes.Red; } }
public void RunSelected() { if (V_Data.SelectedItems.Count == 0) { MessageBox.Show("StartLine을 지정해 주십시오. 마우스 오른쪽 버튼을 이용하십시오."); return; } CPacketStruct cp = GetStructParser(V_Data.SelectedItems[0].Index); if (cp.IsDynamicPacket) { cp.MakePacket(_endian == Endians.Big); } if (_sendFunc == null) { return; } _sendFunc(cp.PacketBuffer, 0, cp.PacketDataSize, cp); }
public void AddNewItem(String msgText, String name = null, bool allowSameMsg = false) { if (msgText.Trim().Length == 0) { MessageBox.Show("메시지가 비었습니다."); return; } #region 기존에 같은 이름이 있는지 검사후 있으면 이름 붙여줌. List <object> names = V_Data.GetAColumnData(0); name = (name == null)?"Untitled" : name; String newName = name; int count = 0; while (Directory.Exists(_packetDir + "\\" + (newName)) == true) { newName = name + (count++); } #endregion #region 같은 Text가 있으면 같은 라인을 선택해 줌.. 아니면 추가.. if (allowSameMsg == false) { for (int i = 0; i < V_Data.RowCount; i++) { String msg = V_Data.RowRelativeObject(i)["msg"] as String; if (msg.CompareTo(msgText) == 0) { V_Data.ReleaseSelection(); V_Data.Rows[i].Selected = true; return;///같은 item은 추가하지 않음.. } } } #endregion #region 새 디렉토리 만들고 Msg.txt파일 만들어 내용 넣어줌. String newDir = _packetDir + "\\" + newName; try { Directory.CreateDirectory(newDir); } catch //이미 있는 경우.. 그냥 지나침.. { } if (msgText == null) { msgText = ""; } File.WriteAllText(newDir + "\\Msg.txt", msgText); #endregion #region 표에 줄 삽입 CPacketStruct parser = new CPacketStruct(); Dictionary <String, object> rels = new Dictionary <string, object>(); parser.IsStringWithNullEnd = _isStringWithNullEnd; parser.Endian = _endian; parser.StringEncoding = _strEncoding; String msgName = newName; bool integrity; try { parser.MakePacket(msgText, _endian == Endians.Big); integrity = true; } catch (Exception e) { MessageBox.Show(msgName + ":" + e.Message); integrity = true; } rels["integrity"] = integrity; rels["parser"] = parser; rels["msg"] = msgText; EasyGridRow row = V_Data.AddARow(rels, new object[] { false, msgName, "edit", "send", "X", "", }); if (integrity == false) { (row[(int)Titles.name] as EasyGridTextBoxCell).FontColor = Color.Red; } if (allowSameMsg == true) { row.Selected = true; } #endregion V_Data.RefreshList(); saveNameList(); }
void initList() { V_Data.ClearData(); String listDir = _packetDir = _baseDir + "\\PacketList"; String orderFile = _packetDir + "\\ListOrder.txt"; makeNewOrderIfNotExists(); List <String> listOrder = new List <string>(); #region 순서를 가져옴 StreamReader sr = new StreamReader(File.OpenRead(orderFile)); String line; String rootDir = Directory.GetCurrentDirectory() + "\\"; while ((line = sr.ReadLine()) != null) { if (line.Trim().Length > 0) { if (line.IndexOf(rootDir) == 0) { listOrder.Add(line); } else { listOrder.Add(rootDir + line); } } } sr.Close(); #endregion //if (Directory.Exists(listDir) == false) Directory.CreateDirectory(listDir); //else { CPacketStruct parser;// = new CStructParser(); //foreach (String dir in Directory.GetDirectories(listDir)) foreach (String dir in listOrder) { if (dir.Substring(dir.LastIndexOf("\\") + 1).Equals("Backups")) { continue; //백업디렉토리는 제외.. } String Msg = ""; Dictionary <String, object> rels = new Dictionary <string, object>(); try { if (File.Exists(dir + "\\Msg.txt") == false) { MessageBox.Show(dir + "\\Msg.txt 가 없습니다.메시지를 다시 작성하십시오.");//필수파일 File.WriteAllText(dir + "\\Msg.txt", ""); } else { Msg = File.ReadAllText(dir + "\\Msg.txt"); } } catch { continue; } String comment = ""; if (File.Exists(dir + "\\Comment.txt")) { comment = File.ReadAllText(dir + "\\Comment.txt"); } Dictionary <String, String> states = new Dictionary <string, string>(); if (File.Exists(dir + "\\States.txt")) { String[] lines = File.ReadAllLines(dir + "\\States.txt"); for (int i = 0; i < lines.Length; i++) { String[] tokens = lines[i].Split("=;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length > 1) { states[tokens[0].ToLower().Trim()] = tokens[1].ToLower().Trim(); } } } bool isChecked = (states.ContainsKey("check")) ? (states["check"].Equals("y") || states["check"].Equals("true")) : false; parser = new CPacketStruct(); parser.IsStringWithNullEnd = _isStringWithNullEnd; parser.Endian = _endian; parser.StringEncoding = _strEncoding; String msgName = dir.Substring(dir.LastIndexOf("\\") + 1); bool integrity; try { parser.MakePacket(Msg, _endian == Endians.Big); integrity = true; } catch (Exception e) { MessageBox.Show(msgName + ":" + e.Message); integrity = true; } rels["integrity"] = integrity; rels["parser"] = parser; rels["msg"] = Msg; EasyGridRow row = V_Data.AddARow(rels, new object[] { isChecked, msgName, "edit", "send", "X", comment }); if (integrity == false) { (row[(int)Titles.name] as EasyGridTextBoxCell).FontColor = Color.Red; } if (isChecked) { row.RowBackMode = RowBackModes.Gray; } } } if (V_Data.Rows.Count > 0) { V_Data.Rows[0].RowBackMode = FormAdders.EasyGridViewCollections.RowBackModes.Red; //V_Data.Rows[0].RowBackCustomColor = Color.FromArgb(255, 222, 222); } }
public void initList() { V_Data.ClearData(); //if (packetDir != null) _packetDir = packetDir; if (_packetDir == null) { return; } String listDir = _packetDir;// = _baseDir+"\\PacketList"; String orderFile = _packetDir + "\\ListOrder.txt"; makeNewOrderIfNotExists(); List <String> listOrder = new List <string>(); #region 순서를 가져옴 StreamReader sr = new StreamReader(File.OpenRead(orderFile)); String line; //String rootDir = Directory.GetCurrentDirectory() + "\\"; while ((line = sr.ReadLine()) != null) { if (line.Trim().Length > 0) { listOrder.Add(line); //if (line.IndexOf(rootDir) == 0) listOrder.Add(line); //else listOrder.Add(rootDir + line); } } sr.Close(); #endregion String[] dirs = Directory.GetDirectories(_packetDir); for (int i = 0; i < dirs.Length; i++) { String name = dirs[i].Substring(dirs[i].LastIndexOf("\\") + 1); if (name.Equals("Backups")) { continue; //백업디렉토리는 제외.. } if (listOrder.Contains(name) == false) //만일 리스트에 없으면.. { File.Delete(orderFile); makeNewOrderIfNotExists(); listOrder.Clear(); for (int d = 0; d < dirs.Length; d++)//새로만듬.. { name = dirs[i].Substring(dirs[i].LastIndexOf("\\") + 1); if (name.Equals("Backups")) { continue; //백업디렉토리는 제외.. } listOrder.Add(name); } break; } } //if (Directory.Exists(listDir) == false) Directory.CreateDirectory(listDir); //else { //CStructParser parser;// = new CStructParser(); //foreach (String dir in Directory.GetDirectories(listDir)) foreach (String name in listOrder) { String Msg = ""; bool integrity = false; String path = _packetDir + "\\" + name; String msgXml = path + "\\Msg.xml"; String msgTxt = path + "\\Msg.txt"; CPacketStruct parser = new CPacketStruct(); IList <CPacketItem> itemsList = null; Dictionary <String, object> rels = new Dictionary <string, object>(); //try { if (File.Exists(msgXml)) { //try { itemsList = StructXMLParser.XmlToItems(msgXml, parser); Msg = StructXMLParser.ItemsToCode(itemsList); integrity = true; } //catch { /* * integrity = false; * if (File.Exists(msgTxt)) * { * Msg = File.ReadAllText(msgTxt); * } * else * { * * MessageBox.Show(msgXml + "이나 "+ msgTxt+" 가 없습니다.메시지를 다시 작성하십시오.");//필수파일 * File.WriteAllText(msgTxt, ""); * * } */ //} } else if (File.Exists(msgTxt)) { Msg = File.ReadAllText(msgTxt); } else { //MessageBox.Show(msgXml + "이나 " + msgTxt + " 가 없습니다.메시지를 다시 작성하십시오.");//필수파일 if (Directory.Exists(path)) { Directory.Delete(path, true); } //File.WriteAllText(msgTxt,""); } } //catch { // continue; } String comment = ""; if (File.Exists(path + "\\Comment.txt")) { comment = File.ReadAllText(path + "\\Comment.txt"); } Dictionary <String, String> states = new Dictionary <string, string>(); if (File.Exists(path + "\\States.txt")) { String[] lines = File.ReadAllLines(path + "\\States.txt"); for (int i = 0; i < lines.Length; i++) { String[] tokens = lines[i].Split("=;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (tokens.Length > 1) { states[tokens[0].ToLower().Trim()] = tokens[1].ToLower().Trim(); } } } bool isChecked = (states.ContainsKey("check")) ? (states["check"].Equals("y") || states["check"].Equals("true")) : false; parser.IsStringWithNullEnd = _isStringWithNullEnd; parser.Endian = _endian; parser.StringEncoding = _strEncoding; String msgName = name; //try { if (itemsList == null) { parser.MakePacket(Msg, _endian == Endians.Big); integrity = true; } else { //parser.Items.Clear(); parser.Items.CopyFrom(itemsList); //parser.Items = itemsList as List<CPacketItem>; parser.MakePacket(_endian == Endians.Big); } } //catch(Exception e) { // MessageBox.Show(msgName+":"+e.Message); integrity = true; } rels["integrity"] = integrity; rels["parser"] = parser; rels["msg"] = Msg; EasyGridRow row = V_Data.AddARow(rels, new object[] { isChecked, msgName, "edit", "send", "X", comment }); if (integrity == false) { (row[(int)Titles.name] as EasyGridTextBoxCell).FontColor = Color.Red; } if (isChecked) { row.RowBackMode = RowBackModes.Gray; } } } if (V_Data.Rows.Count > 0) { if (_startIndex < V_Data.Rows.Count) { V_Data.Rows[_startIndex].RowBackMode = FormAdders.EasyGridViewCollections.RowBackModes.Red; } //V_Data.Rows[0].RowBackCustomColor = Color.FromArgb(255, 222, 222); } V_Data.RefreshList(); }