Files
fl-knowledge/LP/All_CanShuFenJi.cs
T

536 lines
12 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace LP;
public class All_CanShuFenJi
{
public List<int> mAll_ListID = null;
public List<CanShuFenJi> mList_CanShuFenJi_all = null;
public All_CanShuFenJi()
{
if (mAll_ListID == null)
{
mAll_ListID = new List<int>();
}
mAll_ListID.Clear();
if (mList_CanShuFenJi_all == null)
{
mList_CanShuFenJi_all = new List<CanShuFenJi>();
}
mList_CanShuFenJi_all.Clear();
}
public bool MyContains(int _id)
{
return mAll_ListID.Contains(_id);
}
public int MyFind(int _id_CanShuFenJi)
{
int result = -1;
for (int i = 0; i < mList_CanShuFenJi_all.Count; i++)
{
if (mList_CanShuFenJi_all[i].mID_CanShuFenJi == _id_CanShuFenJi)
{
result = i;
break;
}
}
return result;
}
public void MyDelete1CanShuFenJi(int _index)
{
if (_index >= 0 && _index < mList_CanShuFenJi_all.Count)
{
int mID_CanShuFenJi = mList_CanShuFenJi_all[_index].mID_CanShuFenJi;
mAll_ListID.Remove(mID_CanShuFenJi);
mList_CanShuFenJi_all.RemoveAt(_index);
}
}
public void MyDeleteAll()
{
mAll_ListID.Clear();
mList_CanShuFenJi_all.Clear();
CanShuFenJi.mNextID_static = 1;
}
public void MyAdd1CanShuFenJi(CanShuFenJi _oneCanShuFenJi)
{
int num = MyFind(_oneCanShuFenJi.mID_CanShuFenJi);
if (num < 0)
{
if (_oneCanShuFenJi.mID_CanShuFenJi < CanShuFenJi.mNextID_static)
{
_oneCanShuFenJi.mID_CanShuFenJi = CanShuFenJi.mNextID_static;
}
else if (_oneCanShuFenJi.mID_CanShuFenJi >= CanShuFenJi.mNextID_static)
{
CanShuFenJi.mNextID_static = _oneCanShuFenJi.mID_CanShuFenJi;
}
mList_CanShuFenJi_all.Add(_oneCanShuFenJi);
CanShuFenJi.mNextID_static++;
if (!MyContains(_oneCanShuFenJi.mID_CanShuFenJi))
{
mAll_ListID.Add(_oneCanShuFenJi.mID_CanShuFenJi);
}
}
else
{
mList_CanShuFenJi_all[num].copyFrom(_oneCanShuFenJi);
if (!MyContains(_oneCanShuFenJi.mID_CanShuFenJi))
{
mAll_ListID.Add(_oneCanShuFenJi.mID_CanShuFenJi);
}
}
}
public void Destroy()
{
if (mAll_ListID != null)
{
mAll_ListID.Clear();
}
mAll_ListID = null;
if (mList_CanShuFenJi_all != null)
{
mList_CanShuFenJi_all.Clear();
}
mList_CanShuFenJi_all = null;
}
public int MySaveCanShuFenJi(string _filename)
{
int result = 0;
if (string.IsNullOrEmpty(_filename))
{
MyLog.AddLog("MySaveCanShuFenJi(_fileName) 参数1为空:参数分级数据文件名。");
return result;
}
int result2 = 0;
int num = -1;
CanShuFenJi canShuFenJi = null;
string[] array = new string[2] { "<CanShuFenJi>", "<XianLu>" };
string[] array2 = new string[2] { "</CanShuFenJi>", "</XianLu>" };
try
{
using FileStream fileStream = new FileStream(_filename, FileMode.Create, FileAccess.Write, FileShare.None);
using (StreamWriter streamWriter = new StreamWriter(fileStream, Encoding.UTF8))
{
for (num = 0; num < array.Length; num++)
{
string text = array[num];
string text2 = text;
if (!(text2 == "<CanShuFenJi>"))
{
if (text2 == "<XianLu>")
{
}
continue;
}
result2 = 0;
streamWriter.WriteLine(array[num]);
streamWriter.WriteLine(CanShuFenJi.MyHead_ToString());
for (int i = 0; i < mList_CanShuFenJi_all.Count; i++)
{
canShuFenJi = mList_CanShuFenJi_all[i];
streamWriter.WriteLine(canShuFenJi.MyToString());
}
if (num < array2.Length)
{
streamWriter.WriteLine(array2[num]);
}
else
{
streamWriter.WriteLine(array[num].Replace("<", "</"));
}
}
streamWriter.Close();
}
fileStream.Close();
}
catch (Exception ex)
{
MyLog.AddLog("MySaveCanShuFenJi() 异常:" + ex.Message);
MessageBox.Show("异常:" + ex.Message);
}
return result2;
}
public int MyLoadCanShuFenJi(string _filename)
{
int result = 0;
if (string.IsNullOrEmpty(_filename))
{
MyLog.AddLog("MyLoadCanShuFenJi(_fileName) 参数1为空:参数分级数据文件名。");
return result;
}
if (!File.Exists(_filename))
{
MyLog.AddLog("MyLoadCanShuFenJi(_fileName) 文件未找到! 文件名=" + _filename);
return result;
}
bool flag = false;
int i = -1;
int num = 0;
int num2 = 0;
double num3 = 0.0;
bool flag2 = false;
string[] array = new string[2] { "<CanShuFenJi>", "<XianLu>" };
string[] array2 = new string[2] { "</CanShuFenJi>", "</XianLu>" };
string text = "";
string[] separator = new string[3] { "\r", "\n", "," };
string[] array3 = null;
int num4 = 0;
int num5 = 0;
CanShuFenJi canShuFenJi = new CanShuFenJi();
Encoding[] array4 = new Encoding[6]
{
Encoding.UTF8,
Encoding.Default,
Encoding.ASCII,
Encoding.Unicode,
Encoding.UTF7,
Encoding.UTF32
};
int num6 = 0;
bool flag3 = false;
for (int j = 0; j < array4.Length; j++)
{
try
{
using FileStream fileStream = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.None);
using (StreamReader streamReader = new StreamReader(fileStream, array4[j]))
{
text = streamReader.ReadToEnd().Trim();
if (string.IsNullOrEmpty(text) || text.IndexOf("编码") >= 0 || text.IndexOf("分级") >= 0)
{
num6 = j;
flag3 = true;
}
streamReader.Close();
}
fileStream.Close();
}
catch (Exception)
{
}
if (flag3)
{
break;
}
}
mList_CanShuFenJi_all.Clear();
mAll_ListID.Clear();
using (FileStream fileStream2 = new FileStream(_filename, FileMode.Open, FileAccess.Read, FileShare.None))
{
using (StreamReader streamReader2 = new StreamReader(fileStream2, array4[num6]))
{
while (!streamReader2.EndOfStream)
{
text = streamReader2.ReadLine().Trim();
if (string.IsNullOrEmpty(text))
{
continue;
}
if (!flag)
{
for (i = 0; i < array.Length; i++)
{
if (text.IndexOf(array[i]) >= 0)
{
flag = true;
num = 0;
break;
}
}
continue;
}
if (flag)
{
for (int k = 0; k < array2.Length; k++)
{
if (text.IndexOf(array2[k]) >= 0)
{
flag = false;
i = -1;
break;
}
}
if (!flag)
{
continue;
}
}
string text2 = array[i];
string text3 = text2;
if (!(text3 == "<CanShuFenJi>"))
{
if (text3 == "<XianLu>")
{
num++;
}
continue;
}
array3 = text.Split(separator, StringSplitOptions.RemoveEmptyEntries);
if (num == 0)
{
num5 = 0;
}
if (array3.Length >= 26)
{
canShuFenJi = new CanShuFenJi();
try
{
num4 = Convert.ToInt32(array3[0]);
}
catch (Exception)
{
num4 = CanShuFenJi.mNextID_static;
}
canShuFenJi.mID_CanShuFenJi = num4;
try
{
num4 = Convert.ToInt32(array3[1]);
}
catch (Exception)
{
num4 = -1;
}
canShuFenJi.mXianLuID = num4;
try
{
num4 = Convert.ToInt32(array3[2]);
}
catch (Exception)
{
num4 = -1;
}
canShuFenJi.mID_GanTa = num4;
try
{
num4 = Convert.ToInt32(array3[3]);
}
catch (Exception)
{
num4 = -1;
}
canShuFenJi.mID_TGanTa = num4;
try
{
num3 = Convert.ToDouble(array3[4].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_JYZCD = num3;
try
{
num3 = Convert.ToDouble(array3[5].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_JYZCD = num3;
try
{
num2 = Convert.ToInt32(array3[6]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFenJi_JYZCD = num2;
try
{
num3 = Convert.ToDouble(array3[7].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_JDDZ = num3;
try
{
num3 = Convert.ToDouble(array3[8].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_JDDZ = num3;
try
{
num2 = Convert.ToInt32(array3[9]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFenJi_JDDZ = num2;
try
{
num3 = Convert.ToDouble(array3[10].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_BLXGD = num3;
try
{
num3 = Convert.ToDouble(array3[11].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_BLXGD = num3;
try
{
num2 = Convert.ToInt32(array3[12]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFJ_BLXGD = num2;
try
{
num3 = Convert.ToDouble(array3[13].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_HuGao = num3;
try
{
num3 = Convert.ToDouble(array3[14].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_HuGao = num3;
try
{
num2 = Convert.ToInt32(array3[15]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFJ_HuGao = num2;
try
{
num3 = Convert.ToDouble(array3[16].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_DMQJ = num3;
try
{
num3 = Convert.ToDouble(array3[17].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_DMQJ = num3;
try
{
num2 = Convert.ToInt32(array3[18]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFJ_DMQJ = num2;
try
{
num3 = Convert.ToDouble(array3[19].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mOld_BaoHuJiao = num3;
try
{
num3 = Convert.ToDouble(array3[20].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mNew_BaoHuJiao = num3;
try
{
num2 = Convert.ToInt32(array3[21]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mFJ_BaoHuJiao = num2;
try
{
num3 = Convert.ToDouble(array3[22].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mSTD_JYZ_mm = num3;
try
{
num3 = Convert.ToDouble(array3[23].Trim());
}
catch (Exception)
{
num3 = -1.0;
}
canShuFenJi.mSTD_height_m = num3;
try
{
num2 = Convert.ToInt32(array3[24]);
}
catch (Exception)
{
num2 = -1;
}
canShuFenJi.mState_TuiJian = num2;
try
{
flag2 = Convert.ToBoolean(array3[25]);
}
catch (Exception)
{
flag2 = false;
}
canShuFenJi.mBLQ_need = flag2;
MyAdd1CanShuFenJi(canShuFenJi);
num5++;
}
num++;
}
streamReader2.Close();
}
fileStream2.Close();
}
return num5;
}
}