示例#1
0
        private void btnDelDetail_Click(object sender, EventArgs e)
        {
            if (edtMemo.Visible)
            {
                if (MessageBox.Show("是否确定删除内容?", "注意", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    edtMemo.Text = "";
                }
            }
            else if (gridControlGrid.Visible)
            {
                if (gridMain.SelectedRowsCount <= 0)
                {
                    MessageBox.Show("请选择要删除的行!");
                    return;
                }
                if (gridMain.FocusedRowHandle > -1)
                {
                    int        lHandel = gridMain.FocusedRowHandle;
                    detailView _lInfo  = this.mainView[this.gridMain.GetDataSourceRowIndex(lHandel)];
                    if (MessageBox.Show("是否确定删除该行内容(代码值" + _lInfo.code + ",属性值" + _lInfo.name + ")?", "注意", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        mainView.Remove(_lInfo);
                        this.gridControlGrid.DataSource = mainView;
                        this.gridControlGrid.RefreshDataSource();

                        btnSave.PerformClick();
                    }
                }
            }
        }
示例#2
0
        private void btnAddDetail_Click(object sender, EventArgs e)
        {
            //如果是表格形式
            if (gridControlGrid.Visible)
            {
                fmEnterContent frmCon = new fmEnterContent();
                frmCon.ShowDialog();
                if (frmCon.DialogResult == DialogResult.OK)
                {
                    string strValue  = frmCon.StrValue;
                    string strName   = frmCon.StrName;
                    string strMemo   = frmCon.StrMemo;
                    string strDetail = frmCon.StrDetail;

                    List <detailView> dataList = new List <detailView>();
                    detailView        item     = new detailView();
                    item.code   = strValue;
                    item.name   = strName;
                    item.note   = strMemo;
                    item.detail = strDetail;
                    dataList.Add(item);
                    addDataToView(dataList, false);

                    //直接保存
                    btnSave.PerformClick();
                }
            }
            if (edtMemo.Visible)
            {
                edtMemo.Enabled = true;
            }
        }
示例#3
0
        private void ShowToolTipsGrid()
        {
            toolinfo = new ToolTipControllerShowEventArgs();
            detailView detailData = gridMain.GetFocusedRow() as detailView;

            if (detailData != null)
            {
                toolinfo.AllowHtmlText = DefaultBoolean.True;
                toolinfo.ToolTip       = NewLineStr(detailData.detail.Replace('#', '\r').Replace('^', '\n'), 50);
                toolinfo.Rounded       = true; //圆角
                toolinfo.RoundRadius   = 7;    //圆角率
                toolinfo.ToolTipType   = ToolTipType.Standard;
                SetToolTipsSetting(toolinfo, pubDefines.toolTipsType.type_GridDetail);
                if (toolinfo.Title != "" || toolinfo.ToolTip != "")
                {
                    Point pLocate = new Point(MousePosition.X, MousePosition.Y); // 0,0 是左上角
                    //pLocate = gridControlGrid.PointToScreen(pLocate); // p.X, p.Y 是控件左上角在屏幕上的坐标
                    SetToolTipsControllerSetting(toolTipControllerGrid, pubDefines.toolTipsType.type_GridDetail);
                    if (toolinfo.ToolTip != "")
                    {
                        toolTipControllerGrid.ShowHint(toolinfo, pLocate);
                    }
                    else
                    {
                        toolTipControllerGrid.HideHint();
                    }
                }
            }
        }
示例#4
0
        /// <summary>
        /// 显示grid的内容
        /// </summary>
        private void ShowGridContent()
        {
            string msg = string.Empty;

            #region 显示grid中的内容
            string aaa = "";
            try
            {
                string gridPath = Directory.GetFiles(pubDefines.allPathDefine.mainSavePath, "grid_" + listMain.SelectedItem.ToString() + ".txt").FirstOrDefault();
                if (gridPath != "")
                {
                    string[] contents = { };
                    contents = pubFunction.ReadContentFromTxtAll(gridPath, out msg);
                    if (!string.IsNullOrWhiteSpace(msg))
                    {
                        //MessageBox.Show("内容加载失败!" + msg);
                        mainView.Clear();
                        gridControlGrid.DataSource = mainView;
                        gridControlGrid.RefreshDataSource();
                        return;
                    }
                    else
                    {
                        mainView.Clear();
                        foreach (string detail in contents)
                        {
                            string[]   strCont = detail.Split('\t');
                            detailView item    = new detailView();
                            aaa       = strCont[0].ToString();
                            item.code = strCont[0].ToString();
                            item.name = strCont[1].ToString();
                            item.note = strCont[2].ToString();
                            if (strCont.Length > 3)
                            {
                                item.detail = (strCont[3] ?? "").ToString();
                            }
                            mainView.Add(item);
                        }
                        gridControlGrid.DataSource = mainView;
                        gridControlGrid.RefreshDataSource();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "," + aaa);
                gridControlGrid.DataSource = null;
                gridControlGrid.RefreshDataSource();
                return;
            }
            #endregion
        }
示例#5
0
        private void btnExcel_Click(object sender, EventArgs e)
        {
            if (listMain.SelectedItem != null)
            {
                //打开excel选择框
                OpenFileDialog frm = new OpenFileDialog();
                frm.Filter = "Excel文件(*.xls,xlsx)|*.xls;*.xlsx";
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    string    excelName = frm.FileName;
                    DataTable dt        = AsPoseHelper.ExcelToDataTable(excelName, null, false, false);
                    if ((dt != null) && (dt.Rows.Count > 0))
                    {
                        List <detailView> dataList = new List <detailView>();
                        for (int i = 0; i < dt.Rows.Count - 1; i++)
                        {
                            string strValue  = dt.Rows[i][0].ToString();
                            string strName   = dt.Rows[i][1].ToString();
                            string strMemo   = dt.Rows[i][2].ToString();
                            string strDetail = (dt.Rows[i][3] ?? "").ToString();

                            detailView item = new detailView();
                            item.code   = strValue;
                            item.name   = strName;
                            item.note   = strMemo;
                            item.detail = strDetail;
                            dataList.Add(item);
                        }
                        if (System.Windows.Forms.MessageBox.Show("是否覆盖现有的数据?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            addDataToView(dataList, true);
                        }
                        else
                        {
                            addDataToView(dataList, false);
                        }
                        //直接保存
                        btnSave.PerformClick();
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择一个项目");
                return;
            }
        }
示例#6
0
 /// <summary>
 /// excel导入的数据添加到grid中
 /// </summary>
 /// <param name="dataDetailList">数据</param>
 /// <param name="isFold">是否覆盖</param>
 private void addDataToView(List <detailView> dataDetailList, bool isFold = false)
 {
     if (isFold)
     {
         mainView.Clear();
     }
     for (int i = 0; i < dataDetailList.Count; i++)
     {
         detailView detail = new detailView();
         detail.code   = dataDetailList[i].code;
         detail.name   = dataDetailList[i].name;
         detail.note   = dataDetailList[i].note;
         detail.detail = dataDetailList[i].detail;
         mainView.Add(detail);
     }
     this.gridControlGrid.DataSource = mainView;
     this.gridControlGrid.RefreshDataSource();
 }
示例#7
0
        private void btnUpdateByDataBase_Click(object sender, EventArgs e)
        {
            if (gridControlGrid.Visible)
            {
                MyKeyValueSetting currSetting;
                fmDataBase        frm = new fmDataBase();
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    currSetting = frm.currConnection;
                    try
                    {
                        SqlConnection con = new SqlConnection();
                        con.ConnectionString = currSetting.ConnectString;
                        con.Open();

                        string[] tableArray = currSetting.table.Split(';');
                        string[] fieldArray = currSetting.column.Split(';');
                        string   sSql       = string.Empty;
                        for (int i = 0; i < tableArray.Length; i++)
                        {
                            sSql += "select " + fieldArray[i] + " from " + tableArray[i] + "\r\n";
                            sSql += "union" + "\r\n";
                        }
                        if (!string.IsNullOrEmpty(sSql))
                        {
                            sSql = sSql.Substring(0, sSql.Length - 7);
                        }
                        SqlCommand com = new SqlCommand();
                        com.Connection  = con;
                        com.CommandType = CommandType.Text;
                        com.CommandText = sSql;
                        SqlDataReader dr = com.ExecuteReader();//执行SQL语句

                        List <detailView> dataList = new List <detailView>();
                        while (dr.Read())
                        {
                            string strValue  = dr.IsDBNull(0) ? "" : dr.GetValue(0).ToString();
                            string strName   = dr.IsDBNull(1) ? "" : dr.GetValue(1).ToString();
                            string strMemo   = dr.IsDBNull(2) ? "" : dr.GetValue(2).ToString();
                            string strDetail = dr.IsDBNull(3) ? "" : dr.GetValue(3).ToString();

                            detailView item = new detailView();
                            item.code   = strValue;
                            item.name   = strName;
                            item.note   = strMemo.Replace('\t', ' ').Replace('\r', '#').Replace('\n', '^');
                            item.detail = strDetail.Replace('\t', ' ').Replace('\r', '#').Replace('\n', '^');
                            dataList.Add(item);
                        }
                        dr.Close();  //关闭执行
                        con.Close(); //关闭数据库

                        if (System.Windows.Forms.MessageBox.Show("是否覆盖现有的数据?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            addDataToView(dataList, true);
                        }
                        else
                        {
                            addDataToView(dataList, false);
                        }
                        //直接保存
                        btnSave.PerformClick();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            else
            {
                fmDataBase frm = new fmDataBase(false);
                frm.ShowDialog();
            }
        }