/// <summary>保存 /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolSave_Click(object sender, EventArgs e) { CLayer nLay = GetControlInfo(); if (nLay != null) { LayerMod = nLay.Clone(); LayerMod.SaveToDefault(); bSave = false; toolSave.Enabled = bSave; } }
private CLayer GetControlInfo() { CLayer nLay = new CLayer(); nLay = LayerMod.Clone(); nLay.Clear(); try { for (int i = 0; i < nLay.ListCell.Count; i++) { switch (nLay.ListCell[i].ValueType.ToUpper()) { case "STRING": continue; break; case "DATE": string message = ""; string sNew = dGV1.Rows[i].Cells[5].Value.ToString(); bool aa = nLay.ListCell[i].CheckExcel(sNew, ref message); if (!aa) { MessageBox.Show(message, "错误"); return(null); } nLay.ListCell[i].StrValue = message; break; case "INT": case "FLOAT": message = ""; sNew = dGV1.Rows[i].Cells[5].Value.ToString(); aa = nLay.ListCell[i].CheckExcel(sNew, ref message); if (!aa) { MessageBox.Show(message, "错误"); return(null); } nLay.ListCell[i].StrValue = sNew; double f1 = Convert.ToDouble(dGV1.Rows[i].Cells[6].Value.ToString()); nLay.ListCell[i].RatioValue = dGV1.Rows[i].Cells[6].Value.ToString(); break; case "BOOL": string str1 = dGV1.Rows[i].Cells[7].Value.ToString(); str1 = str1.Replace(',', ','); str1 = str1.Replace(';', ','); str1 = str1.Replace(':', ','); str1 = str1.Replace(';', ','); str1 = str1.Replace(':', ','); string[] str2 = str1.Split(','); if (str2.Length < 2) { MessageBox.Show("值范围不能少于2个,不同值之间请用','分开", "格式错误"); return(null); } nLay.ListCell[i].sRange = str1; message = ""; sNew = dGV1.Rows[i].Cells[5].Value.ToString(); aa = nLay.ListCell[i].CheckExcel(sNew, ref message); if (!aa) { MessageBox.Show(message, "错误"); return(null); } nLay.ListCell[i].StrValue = sNew; break; default: break; } } return(nLay); } catch (Exception ex) { MessageBox.Show(ex.Message, "保存失败", MessageBoxButtons.OK); return(null); } }