Beispiel #1
0
    void GetData()
    {
        string             sData  = "";
        List <CBaseObject> lstObj = m_Table.ColumnMgr.GetList();

        foreach (CBaseObject obj in lstObj)
        {
            CColumn col = (CColumn)obj;
            string  sRefTableName = "", sRefColName = "", sRefShowColName = "", sEnumVal = "";
            if (col.RefTable != Guid.Empty)
            {
                CTable refTable = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Find(col.RefTable);
                if (refTable != null)
                {
                    sRefTableName = refTable.Name;
                    if (col.RefCol != Guid.Empty)
                    {
                        CColumn refCol = (CColumn)refTable.ColumnMgr.Find(col.RefCol);
                        if (refCol != null)
                        {
                            sRefColName = refCol.Name;
                        }
                        CColumn refShowCol = (CColumn)refTable.ColumnMgr.Find(col.RefShowCol);
                        if (refShowCol != null)
                        {
                            sRefShowColName = refShowCol.Name;
                        }
                    }
                }
            }
            List <CBaseObject> lstObjEV = col.ColumnEnumValMgr.GetList();
            foreach (CBaseObject objEV in lstObjEV)
            {
                CColumnEnumVal ev = (CColumnEnumVal)objEV;
                sEnumVal += ev.Val + "/";
            }
            sEnumVal = sEnumVal.TrimEnd("/".ToCharArray());

            sData += string.Format("{{ \"id\": \"{0}\",\"Name\":\"{1}\", \"Code\":\"{2}\", \"ColType\":\"{3}\", \"ColLen\":\"{4}\",\"AllowNull\":\"{5}\",\"IsSystem\":\"{6}\",\"DefaultValue\":\"{7}\",\"ColDecimal\":\"{8}\",\"Formula\":\"{9}\",\"RefTable\":\"{10}\",\"RefTableName\":\"{11}\",\"RefCol\":\"{12}\",\"RefColName\":\"{13}\",\"RefShowCol\":\"{14}\",\"RefShowColName\":\"{15}\",\"EnumVal\":\"{16}\",\"IsUnique\":\"{17}\" }},"
                                   , col.Id, col.Name, col.Code, CColumn.ConvertColTypeToString(col.ColType), col.ColLen, col.AllowNull ? 1 : 0, col.IsSystem ? 1 : 0, col.DefaultValue, col.ColDecimal, col.Formula, col.RefTable, sRefTableName, col.RefCol, sRefColName, col.RefShowCol, sRefShowColName, sEnumVal, col.IsUnique ? 1 : 0);
        }
        sData = sData.TrimEnd(",".ToCharArray());
        sData = "[" + sData + "]";
        string sJson = string.Format("{{\"Rows\":{0},\"Total\":\"{1}\"}}"
                                     , sData, 5);

        Response.Write(sJson);
    }
        Control ColumnMapControl(CColumn col)
        {
            //自扩展类优先
            if (!string.IsNullOrEmpty(col.UIControl))
            {
                try
                {
                    object      obj  = Activator.CreateInstance(Type.GetType(col.UIControl));
                    IColumnCtrl ctrl = (IColumnCtrl)obj;
                    ctrl.SetCaption(col.Name + ":");
                    if (BaseObject != null)
                    {
                        ctrl.SetValue(BaseObject.GetColValue(col));
                    }
                    return((Control)ctrl);
                }
                catch
                {
                }
            }
            switch (col.ColType)
            {
            case ColumnType.string_type:
            {
                ExTextBox ctrl = new ExTextBox();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.text_type:
            {
                ExTextBox ctrl = new ExTextBox();
                ctrl.textBox.Multiline  = true;
                ctrl.textBox.ScrollBars = ScrollBars.Both;
                ctrl.Width  = 300;
                ctrl.Height = 100;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.int_type:
            {
                ExTextBox ctrl = new ExTextBox();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.ref_type:
            {
                ExComboBox ctrl = new ExComboBox();
                ctrl.Width = 300;
                CTable         table         = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                CBaseObjectMgr BaseObjectMgr = new CBaseObjectMgr();
                BaseObjectMgr.TbCode = table.Code;
                BaseObjectMgr.Ctx    = Program.Ctx;

                CColumn            RefCol     = (CColumn)table.ColumnMgr.Find(col.RefCol);
                CColumn            RefShowCol = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                List <CBaseObject> lstObj     = BaseObjectMgr.GetList();
                foreach (CBaseObject obj in lstObj)
                {
                    DataItem item = new DataItem();
                    item.name = obj.GetColValue(RefShowCol).ToString();
                    item.Data = obj.GetColValue(RefCol);

                    ctrl.comboBox.Items.Add(item);
                }
                ctrl.comboBox.DropDownStyle = ComboBoxStyle.DropDownList;


                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.enum_type:
            {
                ExComboBox ctrl = new ExComboBox();
                ctrl.Width = 300;
                //引用显示字段优先
                if (col.RefShowCol != Guid.Empty)
                {
                    CTable         table         = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                    CBaseObjectMgr BaseObjectMgr = new CBaseObjectMgr();
                    BaseObjectMgr.TbCode = table.Code;
                    BaseObjectMgr.Ctx    = Program.Ctx;

                    CColumn            RefShowCol = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                    List <CBaseObject> lstObj     = BaseObjectMgr.GetList();
                    foreach (CBaseObject obj in lstObj)
                    {
                        DataItem item = new DataItem();
                        item.name = obj.GetColValue(RefShowCol).ToString();

                        ctrl.comboBox.Items.Add(item);
                    }
                }
                else
                {
                    List <CBaseObject> lstObj = col.ColumnEnumValMgr.GetList();
                    foreach (CBaseObject obj in lstObj)
                    {
                        CColumnEnumVal cev  = (CColumnEnumVal)obj;
                        DataItem       item = new DataItem();
                        item.name = cev.Val;
                        item.Data = cev.Val;

                        ctrl.comboBox.Items.Add(item);
                    }
                }
                ctrl.comboBox.DropDownStyle = ComboBoxStyle.DropDown;

                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.long_type:
            {
                ExTextBox ctrl = new ExTextBox();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);
            }

            case ColumnType.bool_type:
            {
                ExCheckBox ctrl = new ExCheckBox();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.numeric_type:
            {
                ExTextBox ctrl = new ExTextBox();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.datetime_type:
            {
                ExDateTimePicker ctrl = new ExDateTimePicker();
                ctrl.Width = 300;
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }

            case ColumnType.object_type:
            {
                BinaryCtrl ctrl = new BinaryCtrl();
                ctrl.SetCaption(col.Name + ":");
                if (BaseObject != null)
                {
                    ctrl.SetValue(BaseObject.GetColValue(col));
                }
                return(ctrl);

                break;
            }
            }
            return(new ExTextBox());
        }
Beispiel #3
0
    void PostData()
    {
        string id       = Request["id"];
        string Name     = Request["Name"];
        string Code     = Request["Code"];
        string IsSystem = Request["IsSystem"];
        string GridData = Request["GridData"];

        CUser user = (CUser)Session["User"];

        if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Code))
        {
            Response.Write("数据不完整!");
            return;
        }
        else
        {
            if (Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.FindByName(Name) != null)
            {
                Response.Write("相同名称的表已经存在!");
                return;
            }
            if (Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.FindByCode(Code) != null)
            {
                Response.Write("相同编码的表已经存在!");
                return;
            }

            CTable table = new CTable();
            table.Ctx      = Global.GetCtx(Session["TopCompany"].ToString());
            table.Id       = new Guid(id);
            table.Name     = Name;
            table.Code     = Code;
            table.IsSystem = Convert.ToBoolean(IsSystem);
            table.IsFinish = true;
            table.Creator  = user.Id;
            //系统字段
            {
                CColumn col = new CColumn();
                col.Ctx         = table.Ctx;
                col.FW_Table_id = table.Id;
                col.Name        = "id";
                col.Code        = "id";
                col.ColType     = ColumnType.guid_type;
                col.ColLen      = 16;
                col.AllowNull   = false;
                col.IsSystem    = true;
                col.IsUnique    = true;
                col.IsVisible   = false;
                col.Idx         = 0;
                col.Creator     = user.Id;
                table.ColumnMgr.AddNew(col);

                col             = new CColumn();
                col.Ctx         = table.Ctx;
                col.FW_Table_id = table.Id;
                col.Name        = "创建时间";
                col.Code        = "Created";
                col.ColType     = ColumnType.datetime_type;
                col.ColLen      = 8;
                //col.DefaultValue = "getdate()";
                col.AllowNull = true;
                col.IsSystem  = true;
                col.IsUnique  = false;
                col.IsVisible = false;
                col.Idx       = 1;
                col.Creator   = user.Id;
                table.ColumnMgr.AddNew(col);

                col             = new CColumn();
                col.Ctx         = table.Ctx;
                col.FW_Table_id = table.Id;
                col.Name        = "创建者";
                col.Code        = "Creator";
                col.ColType     = ColumnType.ref_type;
                CTable tableUser = (CTable)Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.FindByCode("B_User");
                Guid   guidUid   = Guid.Empty;
                Guid   guidUname = Guid.Empty;
                if (tableUser != null)
                {
                    col.RefTable = tableUser.Id;
                    CColumn colUid = tableUser.ColumnMgr.FindByCode("id");
                    col.RefCol = colUid.Id;
                    guidUid    = col.RefCol;
                    CColumn colUname = tableUser.ColumnMgr.FindByCode("name");
                    col.RefShowCol = colUname.Id;
                    guidUname      = col.RefShowCol;
                }
                col.ColLen = 16;
                //col.DefaultValue = "0";
                col.AllowNull = true;
                col.IsSystem  = true;
                col.IsUnique  = false;
                col.IsVisible = false;
                col.Idx       = 2;
                col.Creator   = user.Id;
                table.ColumnMgr.AddNew(col);

                col             = new CColumn();
                col.Ctx         = table.Ctx;
                col.FW_Table_id = table.Id;
                col.Name        = "修改时间";
                col.Code        = "Updated";
                col.ColType     = ColumnType.datetime_type;
                col.ColLen      = 8;
                //col.DefaultValue = "getdate()";
                col.AllowNull = true;
                col.IsSystem  = true;
                col.IsUnique  = false;
                col.IsVisible = false;
                col.Idx       = 3;
                col.Creator   = user.Id;
                table.ColumnMgr.AddNew(col);

                col             = new CColumn();
                col.Ctx         = table.Ctx;
                col.FW_Table_id = table.Id;
                col.Name        = "修改者";
                col.Code        = "Updator";
                col.ColType     = ColumnType.ref_type;
                if (tableUser != null)
                {
                    col.RefTable   = tableUser.Id;
                    col.RefCol     = guidUid;
                    col.RefShowCol = guidUname;
                }
                col.ColLen = 16;
                //col.DefaultValue = "0";
                col.AllowNull = true;
                col.IsSystem  = true;
                col.IsUnique  = false;
                col.IsVisible = false;
                col.Idx       = 4;
                col.Creator   = user.Id;
                table.ColumnMgr.AddNew(col);
            }
            //自定义字段
            int      iLastIdx = 4;
            string[] arr1     = Regex.Split(GridData, ";");
            foreach (string str1 in arr1)
            {
                if (str1.Length == 0)
                {
                    continue;
                }
                iLastIdx++;

                string[] arr2 = Regex.Split(str1, ",");
                CColumn  col  = new CColumn();
                col.Ctx          = table.Ctx;
                col.FW_Table_id  = table.Id;
                col.Id           = new Guid(arr2[0]);
                col.Name         = arr2[1];
                col.Code         = arr2[2];
                col.ColType      = CColumn.ConvertStringToColType(arr2[3]);
                col.ColLen       = Convert.ToInt32(arr2[4]);
                col.AllowNull    = (arr2[5] == "1")?true:false;
                col.IsSystem     = (arr2[6] == "1") ? true : false;
                col.IsUnique     = (arr2[17] == "1") ? true : false;
                col.IsVisible    = true;
                col.DefaultValue = arr2[7];
                col.ColDecimal   = (arr2[8] != "") ? Convert.ToInt32(arr2[8]) : 0;
                col.Formula      = arr2[9];
                if (col.ColType == ColumnType.ref_type)
                {
                    col.RefTable   = new Guid(arr2[10]);
                    col.RefCol     = new Guid(arr2[12]);
                    col.RefShowCol = new Guid(arr2[14]);
                }
                if (arr2[16].Trim() != "")
                {
                    col.ColumnEnumValMgr.RemoveAll();
                    string[] arrEnum = Regex.Split(arr2[16].Trim(), "/");
                    for (int i = 0; i < arrEnum.Length; i++)
                    {
                        string         sEnumVal = arrEnum[i];
                        CColumnEnumVal ev       = new CColumnEnumVal();
                        ev.Ctx          = col.Ctx;
                        ev.FW_Column_id = col.Id;
                        ev.Val          = sEnumVal;
                        ev.Idx          = i;
                        col.ColumnEnumValMgr.AddNew(ev);
                    }
                }
                col.Idx     = iLastIdx;
                col.Creator = user.Id;
                table.ColumnMgr.AddNew(col);
            }

            Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.AddNew(table);

            if (!CTable.CreateDataTable(table))
            {
                Response.Write("创建表失败!");
                return;
            }
            if (!Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Save(true))
            {
                Response.Write("添加失败!");
                return;
            }
        }
    }
Beispiel #4
0
    void PostData()
    {
        string Name     = Request["Name"];
        string Code     = Request["Code"];
        string IsSystem = Request["IsSystem"];
        string GridData = Request["GridData"];

        CUser user = (CUser)Session["User"];

        if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Code))
        {
            Response.Write("数据不完整!");
            return;
        }
        else
        {
            if (!m_Table.Name.Equals(Name, StringComparison.OrdinalIgnoreCase) &&
                Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.FindByName(Name) != null)
            {
                Response.Write("相同名称的表已经存在!");
                return;
            }
            if (!m_Table.Code.Equals(Code, StringComparison.OrdinalIgnoreCase) &&
                Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.FindByCode(Code) != null)
            {
                Response.Write("相同编码的表已经存在!");
                return;
            }

            m_Table.Name     = Name;
            m_Table.Code     = Code;
            m_Table.IsSystem = Convert.ToBoolean(IsSystem);
            m_Table.IsFinish = true;
            m_Table.Updator  = user.Id;

            //自定义字段
            int      iLastIdx = 4;
            string[] arr1     = Regex.Split(GridData, ";");
            SortedList <Guid, Guid> sortColID = new SortedList <Guid, Guid>();
            foreach (string str1 in arr1)
            {
                if (str1.Length == 0)
                {
                    continue;
                }
                iLastIdx++;

                string[] arr2   = Regex.Split(str1, ",");
                Guid     guidID = new Guid(arr2[0]);
                if (sortColID.ContainsKey(guidID))
                {
                    continue;
                }

                sortColID.Add(guidID, guidID);
                CColumn col = (CColumn)m_Table.ColumnMgr.Find(guidID);
                if (col == null)
                {
                    col             = new CColumn();
                    col.Ctx         = m_Table.Ctx;
                    col.FW_Table_id = m_Table.Id;
                    col.Id          = guidID;
                    col.Creator     = user.Id;
                    m_Table.ColumnMgr.AddNew(col);
                }
                else
                {
                    col.Updator = user.Id;
                    m_Table.ColumnMgr.Update(col);
                }
                col.Name         = arr2[1];
                col.Code         = arr2[2];
                col.ColType      = CColumn.ConvertStringToColType(arr2[3]);
                col.ColLen       = Convert.ToInt32(arr2[4]);
                col.AllowNull    = (arr2[5] == "1")?true:false;
                col.IsSystem     = (arr2[6] == "1") ? true : false;
                col.IsUnique     = (arr2[17] == "1") ? true : false;
                col.IsVisible    = true;
                col.DefaultValue = arr2[7];
                col.ColDecimal   = (arr2[8] != "") ? Convert.ToInt32(arr2[8]) : 0;
                col.Formula      = arr2[9];
                if (col.ColType == ColumnType.ref_type)
                {
                    col.RefTable   = new Guid(arr2[10]);
                    col.RefCol     = new Guid(arr2[12]);
                    col.RefShowCol = new Guid(arr2[14]);
                }
                if (arr2[16].Trim() != "")
                {
                    col.ColumnEnumValMgr.RemoveAll();
                    string[] arrEnum = Regex.Split(arr2[16].Trim(), "/");
                    for (int i = 0; i < arrEnum.Length; i++)
                    {
                        string         sEnumVal = arrEnum[i];
                        CColumnEnumVal ev       = new CColumnEnumVal();
                        ev.Ctx          = col.Ctx;
                        ev.FW_Column_id = col.Id;
                        ev.Val          = sEnumVal;
                        ev.Idx          = i;
                        col.ColumnEnumValMgr.AddNew(ev);
                    }
                }
                col.Idx = iLastIdx;
            }
            //要删除的字段
            SortedList <Guid, Guid> sortOldColID = new SortedList <Guid, Guid>();
            List <CBaseObject>      lstOldCol    = m_Table.ColumnMgr.GetList();
            foreach (CBaseObject objOld in lstOldCol)
            {
                CColumn col = (CColumn)objOld;
                if (col.Code.Equals("id", StringComparison.OrdinalIgnoreCase) ||
                    col.Code.Equals("Created", StringComparison.OrdinalIgnoreCase) ||
                    col.Code.Equals("Creator", StringComparison.OrdinalIgnoreCase) ||
                    col.Code.Equals("Updated", StringComparison.OrdinalIgnoreCase) ||
                    col.Code.Equals("Updator", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                sortOldColID.Add(objOld.Id, objOld.Id);
            }
            foreach (KeyValuePair <Guid, Guid> pair in sortOldColID)
            {
                if (!sortColID.ContainsKey(pair.Key))
                {
                    m_Table.ColumnMgr.Delete(pair.Key);
                }
            }
            //

            Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Update(m_Table);

            if (!CTable.CreateDataTable(m_Table))
            {
                Response.Write("创建表失败!");
                return;
            }
            if (!Global.GetCtx(Session["TopCompany"].ToString()).TableMgr.Save(true))
            {
                Response.Write("修改失败!");
                return;
            }
        }
    }
Beispiel #5
0
        private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            CColumn col = (CColumn)dataGridView.Rows[e.RowIndex].Tag;

            if (col != null)
            {
                ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
                if (prop == null)
                {
                    prop      = new ColPropertySetting();
                    prop.称    = col.Name;
                    prop.默认值  = col.DefaultValue;
                    prop.公式   = col.Formula;
                    prop.小数位数 = col.ColDecimal;
                    if (col.ColType == ColumnType.ref_type)
                    {
                        CTable table = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                        if (table != null)
                        {
                            prop.引用表 = table.Code;
                            CColumn column = (CColumn)table.ColumnMgr.Find(col.RefCol);
                            prop.引用字段 = column.Code;
                            CColumn column2 = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                            prop.引用显示字段 = column2.Code;
                        }
                    }
                    else if (col.ColType == ColumnType.enum_type)
                    {
                        CTable table = (CTable)Program.Ctx.TableMgr.Find(col.RefTable);
                        if (table != null)
                        {
                            prop.引用表 = table.Code;
                            CColumn column2 = (CColumn)table.ColumnMgr.Find(col.RefShowCol);
                            prop.引用显示字段 = column2.Code;
                        }
                        //
                        List <CBaseObject> lstObj   = col.ColumnEnumValMgr.GetList();
                        string             sEnumVal = "";
                        foreach (CBaseObject obj in lstObj)
                        {
                            CColumnEnumVal cev = (CColumnEnumVal)obj;
                            sEnumVal += cev.Val + "\\";
                        }
                        sEnumVal = sEnumVal.TrimEnd("\\".ToCharArray());
                        prop.枚举值 = sEnumVal;
                    }
                    prop.界面控件    = col.UIControl;
                    prop.web界面控件 = col.WebUIControl;

                    col.m_objTempData = prop;
                }
                propertyGrid.SelectedObject = prop;
                propertyGrid.Refresh();
                UpdateRefTable(prop.引用表);

                //if (col.IsSystem))
                //    propertyGrid.Enabled = false;
                //else
                //    propertyGrid.Enabled = true;
            }
        }
Beispiel #6
0
        private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView.Rows[e.RowIndex];
            CColumn         col = (CColumn)row.Tag;

            if (col != null)
            {
                //if (col.m_CmdType != CmdType.AddNew)
                //    col.m_CmdType = CmdType.Update;
                m_Table.ColumnMgr.Update(col);
            }

            if (e.ColumnIndex == 0)
            {
                if (row.Cells[e.ColumnIndex].Value == null)
                {
                    return;
                }
                string sColName = row.Cells[e.ColumnIndex].Value.ToString();
                if (!ValidateColName(sColName))
                {
                    MessageBox.Show("列名只能由字母、数字、下划线组成,且数字不能在前面!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[1];
                if (cbCell.Value == null)
                {
                    cbCell.Value       = "字符型";
                    row.Cells[2].Value = "50";
                    DataGridViewCheckBoxCell ckCell = (DataGridViewCheckBoxCell)row.Cells[3];
                    ckCell.Value = true;
                    DataGridViewCheckBoxCell ckCell2 = (DataGridViewCheckBoxCell)row.Cells[4];
                    ckCell2.Value = false;
                }

                if (col == null)
                {
                    col           = new CColumn();
                    col.Ctx       = Program.Ctx;
                    col.Name      = sColName;
                    col.AllowNull = true;
                    col.IsSystem  = false;
                    col.IsUnique  = false;
                    col.IsVisible = true;
                    //col.m_CmdType = CmdType.AddNew;
                    m_Table.ColumnMgr.AddNew(col);
                    row.Tag = col;

                    ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
                    if (prop == null)
                    {
                        prop      = new ColPropertySetting();
                        prop.称    = col.Name;
                        prop.默认值  = col.DefaultValue;
                        prop.公式   = col.Formula;
                        prop.小数位数 = col.ColDecimal;
                        List <CBaseObject> lstObj   = col.ColumnEnumValMgr.GetList();
                        string             sEnumVal = "";
                        foreach (CBaseObject obj in lstObj)
                        {
                            CColumnEnumVal cev = (CColumnEnumVal)obj;
                            sEnumVal += cev.Val + "\\";
                        }
                        sEnumVal = sEnumVal.TrimEnd("\\".ToCharArray());
                        prop.枚举值 = sEnumVal;

                        col.m_objTempData = prop;
                    }
                    propertyGrid.SelectedObject = prop;
                    propertyGrid.Refresh();
                    UpdateRefTable(prop.引用表);

                    if (col.IsSystem)
                    {
                        propertyGrid.Enabled = false;
                    }
                    else
                    {
                        propertyGrid.Enabled = true;
                    }
                }
            }
        }
Beispiel #7
0
        private void tbtSave_Click(object sender, EventArgs e)
        {
            string sName = txtTableName.Text.Trim();
            string sCode = txtTableCode.Text.Trim();

            if (sName == "")
            {
                MessageBox.Show("名称不能空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTableName.Focus();
                return;
            }
            if (sCode == "")
            {
                MessageBox.Show("编码不能空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtTableCode.Focus();
                return;
            }
            if (!ValidateColName(sCode))
            {
                MessageBox.Show("编码只能由字母、数字、下划线组成,且数字不能在前面!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                txtTableCode.Focus();
                txtTableCode.SelectAll();
                return;
            }
            if (m_Table.m_CmdType == CmdType.AddNew)
            {
                if (Program.Ctx.TableMgr.FindByCode(sCode) != null)
                {
                    MessageBox.Show("相同编码的表已经存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    txtTableCode.Focus();
                    txtTableCode.SelectAll();
                    return;
                }
            }
            else if (!sCode.Equals(m_Table.Code, StringComparison.OrdinalIgnoreCase))
            {
                CTable table = Program.Ctx.TableMgr.FindByCode(sCode);
                if (table != null && table != m_Table)
                {
                    MessageBox.Show("相同编码的表已经存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    txtTableCode.Focus();
                    txtTableCode.SelectAll();
                    return;
                }
            }
            //检查列的合法性
            SortedList arrColName = new SortedList();

            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                if (row.Cells[0].Value == null)
                {
                    continue;
                }
                string sColName = row.Cells[0].Value.ToString().Trim();
                if (sColName == "")
                {
                    MessageBox.Show(string.Format("列名不能空!"), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                if (!ValidateColName(sColName))
                {
                    MessageBox.Show(string.Format("列名只能由字母、数字、下划线组成,且数字不能在前面:{0}", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                if (arrColName.Contains(sColName))
                {
                    MessageBox.Show(string.Format("列名重复:{0}", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    return;
                }
                arrColName.Add(sColName, sColName);

                //
                CColumn col = (CColumn)row.Tag;
                DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[1];
                ColumnType colType = CColumn.ConvertStringToColType(cbCell.Value.ToString());
                if (colType == ColumnType.ref_type)
                {
                    ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
                    if (prop != null)
                    {
                        if (string.IsNullOrEmpty(prop.引用表))
                        {
                            MessageBox.Show(string.Format("{0}列引用表不能空!", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        if (string.IsNullOrEmpty(prop.引用字段))
                        {
                            MessageBox.Show(string.Format("{0}列引用字段不能空!", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        if (string.IsNullOrEmpty(prop.引用显示字段))
                        {
                            MessageBox.Show(string.Format("{0}列引用显示字段不能空!", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                    }
                }
                else if (colType == ColumnType.enum_type)
                {
                    ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
                    if (prop != null)
                    {
                        if (string.IsNullOrEmpty(prop.引用显示字段) &&
                            string.IsNullOrEmpty(prop.枚举值))
                        {
                            MessageBox.Show(string.Format("{0}列至少有引用显示字段或枚举值!", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            return;
                        }
                        if (!string.IsNullOrEmpty(prop.引用显示字段))
                        {
                            if (string.IsNullOrEmpty(prop.引用表))
                            {
                                MessageBox.Show(string.Format("{0}列引用表不能空!", sColName), "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                return;
                            }
                        }
                    }
                }
            }


            m_Table.Name     = sName;
            m_Table.Code     = sCode;
            m_Table.IsSystem = ckIsSystem.Checked;
            m_Table.IsFinish = true;
            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                if (row.Cells[0].Value == null)
                {
                    continue;
                }
                string sColName = row.Cells[0].Value.ToString().Trim();
                DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[1];
                string sColLen = row.Cells[2].Value.ToString().Trim();
                DataGridViewCheckBoxCell ckCell  = (DataGridViewCheckBoxCell)row.Cells[3];
                DataGridViewCheckBoxCell ckCell2 = (DataGridViewCheckBoxCell)row.Cells[4];
                DataGridViewCheckBoxCell ckCell3 = (DataGridViewCheckBoxCell)row.Cells[5];

                CColumn col = (CColumn)row.Tag;
                col.FW_Table_id = m_Table.Id;
                col.Code        = sColName;
                col.ColType     = CColumn.ConvertStringToColType(cbCell.Value.ToString());
                col.ColLen      = Convert.ToInt32(sColLen);
                col.AllowNull   = Convert.ToBoolean(ckCell.Value);
                col.IsSystem    = Convert.ToBoolean(ckCell2.Value);
                col.IsUnique    = Convert.ToBoolean(ckCell3.Value);
                col.Idx         = row.Index;
                ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
                if (prop != null)
                {
                    col.Name         = prop.称;
                    col.DefaultValue = prop.默认值;
                    col.ColDecimal   = prop.小数位数;
                    col.Formula      = prop.公式;
                    if (col.ColType == ColumnType.ref_type)
                    {
                        CTable table = Program.Ctx.TableMgr.FindByCode(prop.引用表);
                        col.RefTable = table.Id;
                        CColumn column = table.ColumnMgr.FindByCode(prop.引用字段);
                        col.RefCol     = column.Id;
                        column         = table.ColumnMgr.FindByCode(prop.引用显示字段);
                        col.RefShowCol = column.Id;
                    }
                    else if (col.ColType == ColumnType.enum_type)
                    {
                        //引用显示字段优先
                        if (!string.IsNullOrEmpty(prop.引用显示字段))
                        {
                            CTable table = Program.Ctx.TableMgr.FindByCode(prop.引用表);
                            col.RefTable = table.Id;
                            CColumn column = table.ColumnMgr.FindByCode(prop.引用显示字段);
                            col.RefShowCol = column.Id;
                        }
                        else
                        {
                            col.ColumnEnumValMgr.RemoveAll();
                            string[] arrItem = prop.枚举值.Split("\\".ToCharArray());
                            for (int i = 0; i < arrItem.Length; i++)
                            {
                                string         sVal = arrItem[i];
                                CColumnEnumVal cev  = new CColumnEnumVal();
                                cev.Ctx          = Program.Ctx;
                                cev.FW_Column_id = col.Id;
                                cev.Val          = sVal;
                                cev.Idx          = i;

                                col.ColumnEnumValMgr.AddNew(cev);
                            }
                        }
                    }
                    col.UIControl    = prop.界面控件;
                    col.WebUIControl = prop.web界面控件;
                }
                m_Table.ColumnMgr.Update(col);
            }

            if (!CTable.CreateDataTable(m_Table))
            {
                MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }
            //if (!m_Table.Save(true))
            if (!Program.Ctx.TableMgr.Save(true))
            {
                MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                return;
            }

            //if (m_Table.m_CmdType== CmdType.AddNew) //新建
            //{
            //    //m_Table = new CTable();
            //    m_Table.Name = sName;
            //    m_Table.Code = sCode;
            //    m_Table.IsSystem = ckIsSystem.Checked;
            //    if (Program.User != null)
            //    {
            //        m_Table.Creator = Program.User.Id;
            //        m_Table.Updator = Program.User.Id;
            //    }
            //    m_Table.Ctx = Program.Ctx;
            //    m_Table.IsFinish = true;
            //    if (!Program.Ctx.TableMgr.AddNew(m_Table))
            //    {
            //        MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //        return;
            //    }
            //    foreach (DataGridViewRow row in dataGridView.Rows)
            //    {
            //        if (row.Cells[0].Value == null)
            //            continue;
            //        string sColName = row.Cells[0].Value.ToString().Trim();
            //        DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[1];
            //        string sColLen = row.Cells[2].Value.ToString().Trim();
            //        DataGridViewCheckBoxCell ckCell = (DataGridViewCheckBoxCell)row.Cells[3];
            //        DataGridViewCheckBoxCell ckCell2 = (DataGridViewCheckBoxCell)row.Cells[4];

            //        CColumn col = (CColumn)row.Tag;
            //        col.FW_Table_id = m_Table.Id;
            //        col.Code = sColName;
            //        col.ColType = CColumn.ConvertStringToColType(cbCell.Value.ToString());
            //        col.ColLen = Convert.ToInt32(sColLen);
            //        col.AllowNull = Convert.ToBoolean(ckCell.Value);
            //        col.IsSystem = Convert.ToBoolean(ckCell2.Value);
            //        col.Idx = row.Index;
            //        ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
            //        if (prop != null)
            //        {
            //            col.Name = prop.名称;
            //            col.DefaultValue = prop.默认值;
            //            col.ColDecimal = prop.小数位数;
            //            col.Formula = prop.公式;
            //            if (col.ColType == ColumnType.ref_type)
            //            {
            //                CTable table = Program.Ctx.TableMgr.FindByCode(prop.引用表);
            //                col.RefTable = table.Id;
            //                CColumn column = table.ColumnMgr.FindByCode(prop.引用字段);
            //                col.RefCol = column.Id;
            //                column = table.ColumnMgr.FindByCode(prop.引用显示字段);
            //                col.RefShowCol = column.Id;
            //            }
            //            col.UIControl = prop.界面控件;
            //            col.WebUIControl = prop.web界面控件;
            //        }
            //        col.Ctx = m_Table.Ctx;

            //        if (!m_Table.ColumnMgr.AddNew(col))
            //        {
            //            MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //            return;
            //        }
            //    }

            //    if (!m_Table.Save(true))
            //    {
            //        MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //        return;
            //    }
            //}
            //else //保存
            //{
            //    m_Table.Name = sName;
            //    m_Table.Code = sCode;
            //    m_Table.IsFinish = true;
            //    m_Table.IsSystem = ckIsSystem.Checked;
            //    if (!Program.Ctx.TableMgr.Update(m_Table))
            //    {
            //        MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //        return;
            //    }
            //    List<CBaseObject> lstCol = m_Table.ColumnMgr.GetList();
            //    List<CColumn> lstDel = new List<CColumn>();
            //    foreach (CBaseObject obj in lstCol)
            //    {
            //        CColumn col = (CColumn)obj;
            //        bool bHas = false;
            //        foreach (DataGridViewRow row in dataGridView.Rows)
            //        {
            //            if (row.Cells[0].Value == null)
            //                continue;
            //            CColumn col2 = (CColumn)row.Tag;
            //            if (col == col2)
            //            {
            //                bHas = true;
            //                break;
            //            }
            //        }
            //        if (!bHas)
            //            lstDel.Add(col);
            //    }
            //    foreach (CColumn col in lstDel)
            //    {
            //        m_Table.ColumnMgr.Delete(col);
            //    }

            //    foreach (DataGridViewRow row in dataGridView.Rows)
            //    {
            //        if (row.Cells[0].Value == null)
            //            continue;
            //        string sColName = row.Cells[0].Value.ToString().Trim();
            //        DataGridViewComboBoxCell cbCell = (DataGridViewComboBoxCell)row.Cells[1];
            //        string sColLen = row.Cells[2].Value.ToString().Trim();
            //        DataGridViewCheckBoxCell ckCell = (DataGridViewCheckBoxCell)row.Cells[3];
            //        DataGridViewCheckBoxCell ckCell2 = (DataGridViewCheckBoxCell)row.Cells[4];

            //        CColumn col = (CColumn)row.Tag;
            //        col.FW_Table_id = m_Table.Id;
            //        col.Code = sColName;
            //        col.ColType = CColumn.ConvertStringToColType(cbCell.Value.ToString());
            //        col.ColLen = Convert.ToInt32(sColLen);
            //        col.AllowNull = Convert.ToBoolean(ckCell.Value);
            //        col.IsSystem = Convert.ToBoolean(ckCell2.Value);
            //        col.Idx = row.Index;
            //        ColPropertySetting prop = (ColPropertySetting)col.m_objTempData;
            //        if (prop != null)
            //        {
            //            col.Name = prop.名称;
            //            col.DefaultValue = prop.默认值;
            //            col.ColDecimal = prop.小数位数;
            //            col.Formula = prop.公式;
            //            if (col.ColType == ColumnType.ref_type)
            //            {
            //                CTable table = Program.Ctx.TableMgr.FindByCode(prop.引用表);
            //                col.RefTable = table.Id;
            //                CColumn column = table.ColumnMgr.FindByCode(prop.引用字段);
            //                col.RefCol = column.Id;
            //                column = table.ColumnMgr.FindByCode(prop.引用显示字段);
            //                col.RefShowCol = column.Id;
            //            }
            //            col.UIControl = prop.界面控件;
            //            col.WebUIControl = prop.web界面控件;
            //        }
            //        col.Ctx = m_Table.Ctx;

            //        if (col.m_CmdType== CmdType.AddNew)
            //        {
            //            if (!m_Table.ColumnMgr.AddNew(col))
            //            {
            //                MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //                return;
            //            }
            //        }
            //        else if (col.m_CmdType == CmdType.Update)
            //        {
            //            if (!m_Table.ColumnMgr.Update(col))
            //            {
            //                MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //                return;
            //            }
            //        }
            //    }
            //    if (!m_Table.Save(true))
            //    {
            //        MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //        return;
            //    }
            //    //排列索引变化,重新加载
            //    m_Table.ColumnMgr.Load(m_Table.ColumnMgr.m_sWhere, true);
            //}
            //if (!CTable.CreateDataTable(m_Table))
            //{
            //    MessageBox.Show(Program.Ctx.LastError, "错误", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            //    return;
            //}


            DialogResult = DialogResult.OK;
        }