예제 #1
0
        /// <summary>
        /// 初始化数据勾选表格。行,列。跟对比字段。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="BaseData">要对比的行</param>
        /// <param name="ShowColumns">展示行的列显示</param>
        /// <param name="MatchField_SupperSet">可选项(超集)里的关联字段,以后做成以逗号分割的</param>
        /// <param name="MatchField_SubSet">已选项(子集)里的关联字段,以后做成以逗号好分割的</param>
        public void PT_ResetList <T>(List <T> BaseData, List <TS_GRID_COL> ShowColumns, string MatchField_SupperSet, string MatchField_SubSet) where T : class
        {
            PV_MatchField_SupperSet = MatchField_SupperSet;
            PV_MatchField_SubSet    = MatchField_SubSet;


            DataTable  lvDT = HelpTXD.EntitiesToDataTable(BaseData);
            DataColumn lvc  = new DataColumn();

            lvc.ColumnName = FSELE;
            lvc.DataType   = typeof(System.Boolean);
            lvDT.Columns.Add(lvc);
            bindingSourceList.DataSource      = lvDT;
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.Columns.Clear();
            DataGridViewCheckBoxColumn lvCheckCol = new DataGridViewCheckBoxColumn();

            lvCheckCol.HeaderText       = "选择";
            lvCheckCol.DataPropertyName = FSELE;
            dataGridView1.Columns.Add(lvCheckCol);
            foreach (TS_GRID_COL lvShow in ShowColumns)
            {
                DataGridViewTextBoxColumn lvTextCol = new DataGridViewTextBoxColumn();
                lvTextCol.DataPropertyName = lvShow.COL_DATA_NAME;
                lvTextCol.HeaderText       = lvShow.COL_TEXT;
                lvTextCol.ReadOnly         = true;
                dataGridView1.Columns.Add(lvTextCol);
            }
            dataGridView1.DataSource = bindingSourceList;
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
        }
예제 #2
0
        public static void DataGridViewtoExcel_withAsk(DataGridView tmpDataTable, String strDefaultFileName)
        {
            SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

            saveFileDialog1.FileName   = strDefaultFileName;
            saveFileDialog1.DefaultExt = "*.xls";
            saveFileDialog1.Filter     = "Excel文件|*.xls";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                HelpTXD.DataGridViewtoExcel(tmpDataTable, saveFileDialog1.FileName);
                HelpTXD.ShowInfo("导出完成。" + saveFileDialog1.FileName);
            }
        }
예제 #3
0
파일: Services.cs 프로젝트: mictxd/helpTXD
        public void Login(ref LoginUserWcf loginUser)
        {
            DataTable lvdt = null;

            try
            {
                loginUser.errorCode = -1;
                string      ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
                IDataAccess dataAccess = DataAccessFactory.CreateDataAccess(ConnectionStringLocalTransaction);
                //IDataAccess dataAccess = DataAccessFactory.CreateDataAccess();
                List <IDbDataParameter> lvParams = new List <IDbDataParameter>();
                lvParams.Add(dataAccess.CreatParameter("@FLogID", loginUser.LogID));
                //登录请求数 在规定时间内必须少于3次。否则不做任何处理。就退出。这个是为安全设计。增加暴力破解的难度
                object lvo      = dataAccess.ExecuteScalar("SELECT COUNT(*) FROM S_LogTry WITH(NOLOCK) WHERE FLogID= @FLogID  AND FDateCreate> DATEADD(ss,-30, GETDATE())", lvParams);
                int    lv尝试登录次数 = 4;
                try{ lv尝试登录次数 = Convert.ToInt32(lvo.ToString()); }catch {}
                ////提供方法执行的上下文环境
                //OperationContext context = OperationContext.Current;
                ////获取传进的消息属性
                //MessageProperties properties = context.IncomingMessageProperties;
                ////获取消息发送的远程终结点IP和端口
                //RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
                //Console.WriteLine(string.Format("Hello {0},You are   from {1}:{2}", name, endpoint.Address, endpoint.Port));
                //string ip= string.Format("Hello {0},You are   from {1}:{2}", name, endpoint.Address, endpoint.Port);

                lvo = dataAccess.ExecuteScalar("INSERT INTO S_LogTry(FLogID,FDateCreate) VALUES( @FLogID,GETDATE())", lvParams);

                if (lv尝试登录次数 > 3)
                {
                    return;
                }

                //验证账户密码

                lvdt = dataAccess.ExecuteDataTable("select *,getdate() as DbSysTime from Mem_User WITH(NOLOCK) WHERE FDeleted = 0 AND FDeleted=0 and FLogID=@FLogID", lvParams);
                if (lvdt.Rows.Count > 0)
                {
                    if (loginUser.Pass == lvdt.Rows[0]["FPassWord"].ToString())
                    {
                        loginUser.Uid = Convert.ToInt32(lvdt.Rows[0]["FUserID"].ToString());

                        loginUser.FirstName = lvdt.Rows[0]["FUserName"].ToString();
                        loginUser.Pass      = "";
                        loginUser.MSG       = "OK";
                        loginUser.timeIn    = Convert.ToDateTime(lvdt.Rows[0]["DbSysTime"]);

                        loginUser.Gid = 0;
                        string mesge = "";
                        loginUser.AX = ""; HelpTXD.ToMD5(loginUser.timeIn.ToString("yyyyMMddHHmmssfff"), ref loginUser.AX, ref mesge);
                        if (mesge == "")
                        {
                            HelpTXD.Key2Base(ref loginUser.AX, ref loginUser.AT);
                            loginUser.Gid       = Convert.ToInt64(dataAccess.ExecuteScalar("INSERT INTO Mem_User_LogIn(FUserID,FSessionKey,FDateLogIn,FDateLogOut)  VALUES(" + loginUser.Uid.ToString() + ",'" + loginUser.AT + "','" + loginUser.timeIn.ToString("yyyy-MM-dd HH:mm:ss") + "',null);select SCOPE_IDENTITY() ", null));
                            loginUser.XT        = CryptoHelper.Encrypt(ConnectionStringLocalTransaction, LoginUserWcf.CytcryptKey);
                            loginUser.errorCode = 0;
                        }
                    }
                    else
                    {
                        loginUser.errorCode = 2; loginUser.MSG = "密码错误";
                    }
                }
                else
                {
                    loginUser.errorCode = 1; loginUser.MSG = "无此账号";
                }
            }
            catch (Exception ex)
            {
                loginUser.errorCode = 3; loginUser.MSG = "未知错误,请查看日志";
                log4net.ILog logsys = log4net.LogManager.GetLogger(LogName);
                logsys.Error(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
예제 #4
0
        public static void DataGridViewtoExcel(List <DataGridView> Grids4Excel, List <string> GridText, string strDefaultFileName)
        {
            if (Grids4Excel == null)
            {
                return;
            }
            if (Grids4Excel.Count == 0)
            {
                return;
            }

            SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

            saveFileDialog1.FileName   = strDefaultFileName;
            saveFileDialog1.DefaultExt = "*.xls";
            saveFileDialog1.Filter     = "Excel文件|*.xls";
            if (saveFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }


            int rowNum;
            int columnNum;
            int columnIndex = 1;
            int maxLineCount;


            string   lvssss = Application.StartupPath + "\\Microsoft.Office.Interop.Excel.dll";
            Assembly ass;
            object   obj;

            ass = Assembly.LoadFile(lvssss);
            obj = ass.CreateInstance("Microsoft.Office.Interop.Excel.ApplicationClass");
            Microsoft.Office.Interop.Excel.Application xlApp = obj as Microsoft.Office.Interop.Excel.Application;
            xlApp.Visible = true;

            xlApp.DefaultFilePath     = "";
            xlApp.DisplayAlerts       = true;
            xlApp.SheetsInNewWorkbook = Grids4Excel.Count;
            object m_objOpt = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Add(true);

            DataGridView lvGrid;

            for (int lvSheetNo = 0; lvSheetNo < Grids4Excel.Count; lvSheetNo++)
            {
                lvGrid            = Grids4Excel[lvSheetNo];
                rowNum            = lvGrid.Rows.Count;
                columnNum         = lvGrid.Columns.Count;
                columnIndex       = 1;
                maxLineCount      = rowNum + 1;
                object[,] objData = new Object[maxLineCount, columnNum];
                columnIndex       = 0;
                for (int i = 0; i < lvGrid.Columns.Count; i++)
                {
                    DataGridViewColumn dc = lvGrid.Columns[i];
                    if (dc.Visible == true && dc.GetType().Name != "DataGridViewButtonColumn")
                    {
                        objData[0, columnIndex] = dc.HeaderText;
                        columnIndex++;
                    }
                }
                string  lvTmpvalue;
                decimal lviTmpValue;
                for (int r = 0; r < rowNum; r++)
                {
                    columnIndex = 0;
                    for (int j = 0; j < columnNum; j++)
                    {
                        if (lvGrid.Columns[j].Visible == true && lvGrid.Columns[j].GetType().Name != "DataGridViewButtonColumn")
                        {
                            if (lvGrid.Rows[r].Cells[j].Value == null)
                            {
                                objData[r + 1, columnIndex] = "";
                            }
                            else
                            {
                                lvTmpvalue = lvGrid.Rows[r].Cells[j].Value.ToString().Trim();
                                if (decimal.TryParse(lvTmpvalue, out lviTmpValue))
                                {
                                    if (lviTmpValue == 0)
                                    {
                                        lvTmpvalue = "";
                                    }
                                }
                                objData[r + 1, columnIndex] = lvTmpvalue;
                            }
                            columnIndex++;
                        }
                    }
                }
                //写入excel
                if (xlBook.Sheets.Count < lvSheetNo + 1)
                {
                    xlBook.Sheets.Add(m_objOpt, m_objOpt, m_objOpt, m_objOpt);
                }
                //xlBook.Sheets.get_Item(lvSheetNo + 1);
                Microsoft.Office.Interop.Excel._Worksheet xlSheet = (Microsoft.Office.Interop.Excel._Worksheet)(xlBook.Sheets.get_Item(1));
                //xlSheet.Range["A1"].Select();
                xlSheet.Activate();
                xlSheet.Name = GridText[lvSheetNo];
                Microsoft.Office.Interop.Excel.Range m_objRange = null;
                m_objRange       = xlSheet.get_Range("A1", m_objOpt);
                m_objRange       = m_objRange.get_Resize(maxLineCount, columnNum);
                m_objRange.Value = objData;
            }

            try
            {
                xlBook.SaveCopyAs(System.Web.HttpUtility.UrlDecode(saveFileDialog1.FileName, System.Text.Encoding.UTF8));
                xlBook.Saved = true;
                xlApp.Quit();
                HelpTXD.ShowInfo("导出完成。" + saveFileDialog1.FileName);
            }
            catch //(Exception ex)
            {
                xlBook.Saved = true;
                xlApp.Quit();
                throw;
            }
        }