Example #1
0
        public override int GetHashCode()
        {
            int hashCode = 2140781431;

            hashCode = hashCode * -1521134295 + XProgress.GetHashCode();
            hashCode = hashCode * -1521134295 + YProgress.GetHashCode();
            return(hashCode);
        }
Example #2
0
        /// <summary>
        /// ��������Excel�ļ�
        /// </summary>
        public static bool ExportToExcel(XProgress xProgress, DataTable dtError, string strFilePath)
        {
            try
            {

                if (File.Exists(strFilePath))
                {
                    try
                    {
                        File.Delete(strFilePath);
                    }
                    catch(Exception exp)
                    {
                        Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                        return false;
                    }

                }

                Application xlApp = new Application();

                Workbook workbook = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                Worksheet worksheet = null;

                xProgress.ShowGifProgress(null);
                xProgress.ShowHint("���ڵ�����������Excel�ļ�...");

                try
                {

                    //д����ֵ
                    DataTable PropertyTable = dtError;
                    //DataTable TopoTable = CCheckApplication.ucTopoErrMap.m_DataTable;

                    #region �������Լ�¼������˼�¼�����
                    if (PropertyTable != null && PropertyTable.Rows.Count != 0)
                    {
                        //����ÿ���ʼ����ͣ�����һ��worksheet
                        Hashtable hashtable = new Hashtable();
                        int index = 1;
                        foreach (DataRow dr in PropertyTable.Rows)
                        {
                            string strChkType = dr["CheckType"].ToString();
                            if (strChkType == "")
                            {
                                continue;
                            }
                            if (!hashtable.Contains(strChkType))
                            {
                                hashtable.Add(strChkType, "");
                                if (index == 1)
                                {
                                    worksheet = (Worksheet)workbook.Worksheets[1]; //ȡ��sheet1
                                    worksheet.Name = strChkType;
                                }
                                else
                                {
                                    worksheet =
                                        (Worksheet)
                                        workbook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                                    worksheet.Name = strChkType;
                                }
                                index++;
                            }
                        }

                        ///��worksheet��д���ֶ���
                        //д���ֶ�
                        List<string> listPropertyFields = GetPropertyListFields();
                        List<string> listTableStructFields = GetStructFields();
                        List<string> listTopoFields = GetTopoListFields();

                        Worksheet tempSheet = null;
                        for (int k = 1; k <= workbook.Sheets.Count; k++)
                        {
                            tempSheet = (Worksheet)workbook.Sheets[k];
                            if (tempSheet.Name.Contains("���˹�ϵ") && tempSheet.Name != "��������˹�ϵ")
                            {
                                for (int i = 0; i < listTopoFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listTopoFields[i];
                                }

                            }
                            else if (tempSheet.Name == "�ṹ������")
                            {
                                for (int i = 0; i < listTableStructFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listTableStructFields[i];
                                }
                            }
                            else
                            {
                                for (int i = 0; i < listPropertyFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listPropertyFields[i];
                                }
                            }

                            Marshal.ReleaseComObject(tempSheet);
                        }

                        int PropertyRowCount = PropertyTable.Rows.Count;
                        int PropertyColumnCount = PropertyTable.Columns.Count;

                        xProgress.ShowProgress(0, PropertyRowCount, 1, null);
                        DataRow[] listDr = null;
                        DataColumn dc;

                        tempSheet = new Worksheet();
                        for (int l = 1; l <= workbook.Sheets.Count; l++)
                        {
                            tempSheet = (Worksheet)workbook.Sheets[l];
                            string strChkType = tempSheet.Name;
                            listDr = PropertyTable.Select("CheckType = '" + strChkType + "'");
                            for (int r = 0; r < listDr.Length; r++)
                            {
                                xProgress.Step();
                                for (int i = 0; i < PropertyColumnCount; i++)
                                {
                                    dc = PropertyTable.Columns[i];

                                    if (strChkType.Contains("���˹�ϵ") && strChkType != "��������˹�ϵ")
                                    {
                                        string Exception = "˳��ţ�Դͼ��ID��Ŀ��ͼ��ID��Ŀ��OID��ԴOID���������ͣ�����ID��ϵͳ����";
                                        if (Exception.Contains(dc.Caption))
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listTopoFields.Count; k++)
                                        {
                                            if (dc.Caption == listTopoFields[k])
                                            {
                                                if (dc.Caption == "�Ƿ�����")
                                                {
                                                    if (Convert.ToBoolean(listDr[r][i]) == false)
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "��";
                                                    }
                                                    else
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "��";
                                                    }
                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }
                                                break;
                                            }
                                        }

                                    }
                                    else if (tempSheet.Name == "�ṹ������")
                                    {
                                        if (dc.Caption == "ͼ��2" || dc.Caption == "��ʶ��2" || dc.Caption == "����ͼ����" ||
                                            dc.Caption == "˳���" || dc.Caption == "Դͼ��ID" || dc.Caption == "Ŀ��ͼ��ID" ||
                                            dc.Caption == "Ŀ��OID" || dc.Caption == "ԴOID" || dc.Caption == "��������" ||
                                            dc.Caption == "����ID" || dc.Caption == "ϵͳ����")
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listTableStructFields.Count; k++)
                                        {
                                            if (dc.Caption == listTableStructFields[k])
                                            {
                                                if (dc.Caption == "�Ƿ�����")
                                                {
                                                    object bIsException = listDr[r][i];

                                                    if (bIsException == null || bIsException.ToString() == "")
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "��";
                                                    }
                                                    else
                                                    {

                                                        if (Convert.ToBoolean(bIsException) == false)
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "��";
                                                        }
                                                        else
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "��";
                                                        }
                                                    }

                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }

                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (dc.Caption == "ͼ��2" || dc.Caption == "��ʶ��2" || dc.Caption == "����ͼ����" ||
                                            dc.Caption == "˳���" || dc.Caption == "Դͼ��ID" || dc.Caption == "Ŀ��ͼ��ID" ||
                                            dc.Caption == "Ŀ��OID" || dc.Caption == "ԴOID" || dc.Caption == "��������" ||
                                            dc.Caption == "����ID" || dc.Caption == "ϵͳ����")
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listPropertyFields.Count; k++)
                                        {
                                            if (dc.Caption == listPropertyFields[k])
                                            {
                                                if (dc.Caption == "�Ƿ�����")
                                                {
                                                    object bIsException = listDr[r][i];

                                                    if (bIsException == null || bIsException.ToString() == "")
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "��";
                                                    }
                                                    else
                                                    {

                                                        if (Convert.ToBoolean(bIsException) == false)
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "��";
                                                        }
                                                        else
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "��";
                                                        }
                                                    }

                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }

                                                break;
                                            }
                                        }
                                    }

                                }
                            }
                            tempSheet.Columns.AutoFit();
                        }

                        if (tempSheet != null)
                        {
                            Marshal.ReleaseComObject(tempSheet);
                            tempSheet = null;
                        }

                    }
                    #endregion

                    xProgress.Hide();
                    //XtraMessageBox.Show("���������¼��Excel�ļ��ɹ�!", "��ʾ");

                    ///����excel�ļ�
                    workbook.Close(true, strFilePath, null);
                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    Marshal.ReleaseComObject(workbook);
                    if (worksheet != null)
                        Marshal.ReleaseComObject(worksheet);
                    GC.Collect();
                    if (xlApp != null)
                    {
                        Process[] pProcess;
                        pProcess = Process.GetProcessesByName("EXCEL"); //�ر�excel����
                        pProcess[0].Kill();
                    }
                    PropertyTable = null;
                    xlApp = null;
                    workbook = null;
                    worksheet = null;

                }
                catch (Exception exp)
                {
                    Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                    xProgress.Hide();

                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    Marshal.ReleaseComObject(workbook);
                    if (worksheet != null)
                        Marshal.ReleaseComObject(worksheet);
                    GC.Collect();
                    if (xlApp != null)
                    {
                        Process[] pProcess;
                        pProcess = Process.GetProcessesByName("EXCEL"); //�ر�excel����
                        pProcess[0].Kill();
                    }
                    //XtraMessageBox.Show(ex.Message);
                    return false;
                }
                finally
                {
                    xProgress.Hide();

                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());
                //GT_CONST.LogAPI.CheckLog.AppendErrLogs(ex.ToString());
                xProgress.Hide();
                //XtraMessageBox.Show(ex.Message);

                return false;

            }
            return true;
        }
Example #3
0
        /// <summary>
        /// 导出错误到Excel文件
        /// </summary>
        public static bool ExportToExcel(XProgress xProgress, DataTable dtError, string strFilePath)
        {
            try
            {
                if (File.Exists(strFilePath))
                {
                    try
                    {
                        File.Delete(strFilePath);
                    }
                    catch (Exception exp)
                    {
                        Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                        return(false);
                    }
                }

                Application xlApp = new Application();

                Workbook  workbook  = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                Worksheet worksheet = null;

                xProgress.ShowGifProgress(null);
                xProgress.ShowHint("正在导出错误结果至Excel文件...");

                try
                {
                    //写入数值
                    DataTable PropertyTable = dtError;
                    //DataTable TopoTable = CCheckApplication.ucTopoErrMap.m_DataTable;

                    #region 导出属性记录表和拓扑记录表错误
                    if (PropertyTable != null && PropertyTable.Rows.Count != 0)
                    {
                        //对于每种质检类型,创建一个worksheet
                        Hashtable hashtable = new Hashtable();
                        int       index     = 1;
                        foreach (DataRow dr in PropertyTable.Rows)
                        {
                            string strChkType = dr["CheckType"].ToString();
                            if (strChkType == "")
                            {
                                continue;
                            }
                            if (!hashtable.Contains(strChkType))
                            {
                                hashtable.Add(strChkType, "");
                                if (index == 1)
                                {
                                    worksheet      = (Worksheet)workbook.Worksheets[1]; //取得sheet1
                                    worksheet.Name = strChkType;
                                }
                                else
                                {
                                    worksheet =
                                        (Worksheet)
                                        workbook.Sheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                                    worksheet.Name = strChkType;
                                }
                                index++;
                            }
                        }

                        ///向worksheet中写入字段名
                        //写入字段
                        List <string> listPropertyFields    = GetPropertyListFields();
                        List <string> listTableStructFields = GetStructFields();
                        List <string> listTopoFields        = GetTopoListFields();

                        Worksheet tempSheet = null;
                        for (int k = 1; k <= workbook.Sheets.Count; k++)
                        {
                            tempSheet = (Worksheet)workbook.Sheets[k];
                            if (tempSheet.Name.Contains("拓扑关系") && tempSheet.Name != "点层内拓扑关系")
                            {
                                for (int i = 0; i < listTopoFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listTopoFields[i];
                                }
                            }
                            else if (tempSheet.Name == "结构符合性")
                            {
                                for (int i = 0; i < listTableStructFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listTableStructFields[i];
                                }
                            }
                            else
                            {
                                for (int i = 0; i < listPropertyFields.Count; i++)
                                {
                                    tempSheet.Cells[1, i + 1] = listPropertyFields[i];
                                }
                            }

                            Marshal.ReleaseComObject(tempSheet);
                        }


                        int PropertyRowCount    = PropertyTable.Rows.Count;
                        int PropertyColumnCount = PropertyTable.Columns.Count;

                        xProgress.ShowProgress(0, PropertyRowCount, 1, null);
                        DataRow[]  listDr = null;
                        DataColumn dc;

                        tempSheet = new Worksheet();
                        for (int l = 1; l <= workbook.Sheets.Count; l++)
                        {
                            tempSheet = (Worksheet)workbook.Sheets[l];
                            string strChkType = tempSheet.Name;
                            listDr = PropertyTable.Select("CheckType = '" + strChkType + "'");
                            for (int r = 0; r < listDr.Length; r++)
                            {
                                xProgress.Step();
                                for (int i = 0; i < PropertyColumnCount; i++)
                                {
                                    dc = PropertyTable.Columns[i];

                                    if (strChkType.Contains("拓扑关系") && strChkType != "点层内拓扑关系")
                                    {
                                        string Exception = "顺序号,源图层ID,目标图层ID,目标OID,源OID,几何类型,规则ID,系统表名";
                                        if (Exception.Contains(dc.Caption))
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listTopoFields.Count; k++)
                                        {
                                            if (dc.Caption == listTopoFields[k])
                                            {
                                                if (dc.Caption == "是否例外")
                                                {
                                                    if (Convert.ToBoolean(listDr[r][i]) == false)
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "否";
                                                    }
                                                    else
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "是";
                                                    }
                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }
                                                break;
                                            }
                                        }
                                    }
                                    else if (tempSheet.Name == "结构符合性")
                                    {
                                        if (dc.Caption == "图层2" || dc.Caption == "标识码2" || dc.Caption == "拓扑图层名" ||
                                            dc.Caption == "顺序号" || dc.Caption == "源图层ID" || dc.Caption == "目标图层ID" ||
                                            dc.Caption == "目标OID" || dc.Caption == "源OID" || dc.Caption == "几何类型" ||
                                            dc.Caption == "规则ID" || dc.Caption == "系统表名")
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listTableStructFields.Count; k++)
                                        {
                                            if (dc.Caption == listTableStructFields[k])
                                            {
                                                if (dc.Caption == "是否例外")
                                                {
                                                    object bIsException = listDr[r][i];

                                                    if (bIsException == null || bIsException.ToString() == "")
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "否";
                                                    }
                                                    else
                                                    {
                                                        if (Convert.ToBoolean(bIsException) == false)
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "否";
                                                        }
                                                        else
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "是";
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }

                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (dc.Caption == "图层2" || dc.Caption == "标识码2" || dc.Caption == "拓扑图层名" ||
                                            dc.Caption == "顺序号" || dc.Caption == "源图层ID" || dc.Caption == "目标图层ID" ||
                                            dc.Caption == "目标OID" || dc.Caption == "源OID" || dc.Caption == "几何类型" ||
                                            dc.Caption == "规则ID" || dc.Caption == "系统表名")
                                        {
                                            continue;
                                        }
                                        for (int k = 0; k < listPropertyFields.Count; k++)
                                        {
                                            if (dc.Caption == listPropertyFields[k])
                                            {
                                                if (dc.Caption == "是否例外")
                                                {
                                                    object bIsException = listDr[r][i];

                                                    if (bIsException == null || bIsException.ToString() == "")
                                                    {
                                                        tempSheet.Cells[r + 2, k + 1] = "否";
                                                    }
                                                    else
                                                    {
                                                        if (Convert.ToBoolean(bIsException) == false)
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "否";
                                                        }
                                                        else
                                                        {
                                                            tempSheet.Cells[r + 2, k + 1] = "是";
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    tempSheet.Cells[r + 2, k + 1] = listDr[r][i];
                                                }

                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            tempSheet.Columns.AutoFit();
                        }

                        if (tempSheet != null)
                        {
                            Marshal.ReleaseComObject(tempSheet);
                            tempSheet = null;
                        }
                    }
                    #endregion

                    xProgress.Hide();
                    //XtraMessageBox.Show("导出错误记录到Excel文件成功!", "提示");

                    ///保存excel文件
                    workbook.Close(true, strFilePath, null);
                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    Marshal.ReleaseComObject(workbook);
                    if (worksheet != null)
                    {
                        Marshal.ReleaseComObject(worksheet);
                    }
                    GC.Collect();
                    if (xlApp != null)
                    {
                        Process[] pProcess;
                        pProcess = Process.GetProcessesByName("EXCEL"); //关闭excel进程
                        pProcess[0].Kill();
                    }
                    PropertyTable = null;
                    xlApp         = null;
                    workbook      = null;
                    worksheet     = null;
                }
                catch (Exception exp)
                {
                    Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                    xProgress.Hide();

                    xlApp.Quit();
                    Marshal.ReleaseComObject(xlApp);
                    Marshal.ReleaseComObject(workbook);
                    if (worksheet != null)
                    {
                        Marshal.ReleaseComObject(worksheet);
                    }
                    GC.Collect();
                    if (xlApp != null)
                    {
                        Process[] pProcess;
                        pProcess = Process.GetProcessesByName("EXCEL"); //关闭excel进程
                        pProcess[0].Kill();
                    }
                    //XtraMessageBox.Show(ex.Message);
                    return(false);
                }
                finally
                {
                    xProgress.Hide();
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());
                //GT_CONST.LogAPI.CheckLog.AppendErrLogs(ex.ToString());
                xProgress.Hide();
                //XtraMessageBox.Show(ex.Message);

                return(false);
            }
            return(true);
        }