public static Color BackColor(DataGridViewCell cell) { EasyGridRow row = (cell.OwningRow as EasyGridRow); RowBackModes rowMode = row.RowBackMode; int rowIndex = row.Index; if (rowMode == RowBackModes.CellColor) { if (row.CustomColorCells.Contains(cell)) { return(cell.Style.BackColor); } else { if (rowIndex % 2 == 0) { return(Color.White); } else { return(Color.FromArgb(244, 244, 255)); } } } else if (rowMode == RowBackModes.CustomColor) { return(row.RowBackCustomColor); } else if (rowMode == RowBackModes.Blue) { return(Color.FromArgb(220, 220, 255)); } else if (rowMode == RowBackModes.Red) { return(Color.FromArgb(255, 220, 220)); } else if (rowMode == RowBackModes.Gray) { return(Color.FromArgb(220, 220, 220)); } else // if (rowMode == EasyGridRow.RowBackModes.None) { if (rowIndex % 2 == 0) { return(Color.White); } else { return(Color.FromArgb(244, 244, 255)); } } }
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 AddNewItem(CPacketStruct parserObj = null, String name = null) { #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 새 디렉토리 만들고 Msg.txt파일 만들어 내용 넣어줌. String newDir = _packetDir + "\\" + newName; if (Directory.Exists(newDir) == false) { Directory.CreateDirectory(newDir); } if (parserObj == null) { parserObj = new CPacketStruct(); DlgMsgMaker dlg = new DlgMsgMaker(parserObj, newDir + "\\Msg.txt", _endian == Endians.Big); DialogResult result = dlg.ShowDialog(); if (result == DialogResult.Abort || result == DialogResult.Cancel) { return; } //parserObj.Items = StructXMLParser.CodeToItems(parserObj.NativeText, parserObj); StructXMLParser.ItemsToXml(parserObj.Items, newDir + "\\Msg.xml", parserObj.Infos); } else { parserObj.MakeMsgText(); CPacketStruct oldObj = parserObj; parserObj = new CPacketStruct(); parserObj.NativeText = oldObj.NativeText; //parserObj.Items = StructXMLParser.CodeToItems(oldObj.NativeText, parserObj); StructXMLParser.ItemsToXml(parserObj.Items, newDir + "\\Msg.xml", parserObj.Infos); } #endregion #region 표에 줄 삽입 Dictionary <String, object> rels = new Dictionary <string, object>(); parserObj.IsStringWithNullEnd = _isStringWithNullEnd; parserObj.Endian = _endian; parserObj.StringEncoding = _strEncoding; String msgName = newName; bool integrity; try { parserObj.MakePacket(_endian == Endians.Big); integrity = true; } catch (Exception e) { MessageBox.Show(msgName + ":" + e.Message); integrity = true; } rels["integrity"] = integrity; rels["parser"] = parserObj; rels["msg"] = parserObj.NativeText; 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; } #endregion V_Data.RefreshList(); saveNameList(); }
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(); }