Beispiel #1
0
        private void tbComboRemoteName_TextChanged(object sender, EventArgs e)
        {
            string ProviderName = tbComboRemoteName.Text;
            if (ProviderName.Trim() == "")
                return;

            InfoDataSet temp = new InfoDataSet();
            temp.SetWizardDesignMode(true);
            temp.RemoteName = ProviderName;
            temp.SetWhere("1=0");
            temp.Active = true;
            tbComboTableName.Text = temp.RealDataSet.Tables[0].TableName;
            String DataSetName = temp.RealDataSet.Tables[0].TableName;
            String ModuleName = temp.RemoteName.Substring(0, temp.RemoteName.IndexOf('.'));
            String SolutionName = System.IO.Path.GetFileNameWithoutExtension(FDTE2.Solution.FullName);
            tbComboTableName_F.Text = CliUtils.GetTableName(ModuleName, DataSetName, SolutionName, "", true);
            tbComboTableName_F.Text = WzdUtils.RemoveQuote(tbComboTableName_F.Text, FClientData.DatabaseType);

            cbDataValueField.Items.Clear();
            cbDataTextField.Items.Clear();
            DataTable dtTableSchema = temp.RealDataSet.Tables[0];
            foreach (DataColumn item in dtTableSchema.Columns)
            {
                cbDataValueField.Items.Add(item.ColumnName);
                cbDataTextField.Items.Add(item.ColumnName);
            }

            if (InternalConnection.State != ConnectionState.Open)
                InternalConnection.Open();
            DataSet ds = new DataSet();
            try
            {
                DbCommand comm = InternalConnection.CreateCommand();
                comm.CommandText = "SELECT * FROM SYS_REFVAL WHERE REFVAL_NO='Auto." + tbComboTableName_F.Text + "'";
                IDbDataAdapter da = WzdUtils.AllocateDataAdapter(FClientData.DatabaseType);
                da.SelectCommand = comm;
                da.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    cbDataValueField.Text = ds.Tables[0].Rows[0]["VALUE_MEMBER"] == null ? String.Empty : ds.Tables[0].Rows[0]["VALUE_MEMBER"].ToString();
                    cbDataTextField.Text = ds.Tables[0].Rows[0]["DISPLAY_MEMBER"] == null ? String.Empty : ds.Tables[0].Rows[0]["DISPLAY_MEMBER"].ToString();
                }
            }
            catch (SqlException sex)
            {
                if (sex.Number == 208)
                {
                    string sSysDBAlias = WzdUtils.GetSystemDBName();
                    ClientType sSysDBType = WzdUtils.GetSystemDBType();
                    DbConnection sysConn = WzdUtils.AllocateConnection(sSysDBAlias, sSysDBType, false);
                    if (sysConn.State != ConnectionState.Open) sysConn.Open();
                    DbCommand comm = sysConn.CreateCommand();
                    comm.CommandText = "SELECT * FROM SYS_REFVAL WHERE REFVAL_NO='Auto." + tbComboTableName_F.Text + "'";
                    IDbDataAdapter da = WzdUtils.AllocateDataAdapter(sSysDBType);
                    da.SelectCommand = comm;
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        cbDataValueField.Text = ds.Tables[0].Rows[0]["VALUE_MEMBER"] == null ? String.Empty : ds.Tables[0].Rows[0]["VALUE_MEMBER"].ToString();
                        cbDataTextField.Text = ds.Tables[0].Rows[0]["DISPLAY_MEMBER"] == null ? String.Empty : ds.Tables[0].Rows[0]["DISPLAY_MEMBER"].ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void btnComboRemoteName_D_Click(object sender, EventArgs e)
        {
            if (radioButtonEntity.Checked)
            {
                EFAssembly.EFClientToolsAssemblyAdapt.RemoteNameEditorDialog remoteNameEditorDialog = new EFAssembly.EFClientToolsAssemblyAdapt.RemoteNameEditorDialog();

                if (remoteNameEditorDialog.RemoteNameEditorDialogForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    tbComboRemoteName_D.Text = remoteNameEditorDialog.ReturnValue;
                    tbComboEntityName_D.Text = remoteNameEditorDialog.ReturnClassName;

                    List<object> refvals = WzdUtils.GetAllDataByTableName("SYS_REFVAL");
                    for (int i = 0; i < refvals.Count; i++)
                    {
                        if ((refvals[i] as SYS_REFVAL).REFVAL_NO == "SL." + tbComboEntityName_D.Text &&
                                lvSelectedFields.SelectedItems[0].Text == (refvals[i] as SYS_REFVAL).VALUE_MEMBER)
                        {
                            cbComboDisplayField_D.Text = (refvals[i] as SYS_REFVAL).DISPLAY_MEMBER;
                            cbComboValueField_D.Text = (refvals[i] as SYS_REFVAL).VALUE_MEMBER;
                            tbOtherFields_D.Text = (refvals[i] as SYS_REFVAL).SELECT_COMMAND;
                            break;
                        }
                    }
                }
            }
            else if (radioButtonInfoCommand.Checked)
            {
                string[] fSelectedList = new string[10];
                string strSelected = "";
                IGetValues aItem = (IGetValues)FInfoDataSet;
                FProviderNameList = aItem.GetValues("RemoteName");
                PERemoteName form = new PERemoteName(FProviderNameList, strSelected);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    tbComboRemoteName_D.Text = form.RemoteName;

                    InfoDataSet ds = new InfoDataSet();
                    ds.SetWizardDesignMode(true);
                    ds.RemoteName = tbComboRemoteName_D.Text;
                    ds.ClearWhere();
                    ds.SetWhere("1=0");
                    ds.Active = true;
                    String DataSetName = ds.RealDataSet.Tables[0].TableName;
                    String ModuleName = ds.RemoteName.Substring(0, ds.RemoteName.IndexOf('.'));
                    String SolutionName = System.IO.Path.GetFileNameWithoutExtension(FDTE2.Solution.FullName);
                    tbComboEntityName_D.Text = CliUtils.GetTableName(ModuleName, DataSetName, SolutionName, "", true);

                    DataSet dsSYS_REFVAL = GetDataFromSYS_REFVAL(tbComboEntityName_D.Text, lvSelectedFields.SelectedItems[0].Text);
                    if (dsSYS_REFVAL.Tables.Count > 0 && dsSYS_REFVAL.Tables[0].Rows.Count > 0)
                    {
                        cbComboDisplayField_D.Text = dsSYS_REFVAL.Tables[0].Rows[0]["DISPLAY_MEMBER"].ToString();
                        cbComboValueField_D.Text = dsSYS_REFVAL.Tables[0].Rows[0]["VALUE_MEMBER"].ToString();
                        tbOtherFields_D.Text = dsSYS_REFVAL.Tables[0].Rows[0]["SELECT_COMMAND"].ToString();
                    }
                }
            }
        }
Beispiel #3
0
        public void GetData(CacheModeType mode)
        {
            string lastDateTime = LastDateTime;
            InfoDataSet ids = new InfoDataSet();
            ids.RemoteName = this.RemoteName;
            ids.PacketRecords = -1;
            ClientType dbType = CliUtils.GetDataBaseType();
            string mark = (dbType == ClientType.ctMsSql || dbType == ClientType.ctOleDB) ? "+" : "||";
            ids.WhereStr = string.Format("{0}{1}{2}>'{3}'", UPDATE_DATE, mark, UPDATE_TIME, lastDateTime);
            DateTime datetime =DateTime.Now;

            ids.Active = true;

            if (ids.RealDataSet.Tables[0].Rows.Count > 0)
            {
                if (mode == CacheModeType.All)
                {
                    RealDataSet.Clear();
                    ids.SetWhere(string.Format("{0}='I'or {0}='M'", UPDATE_STATE));
                }
                else if (mode == CacheModeType.Smart)
                {
                    DataRow[] rowDeleteDB = ids.RealDataSet.Tables[0].Select(string.Format("{0}='D'", UPDATE_STATE));
                    foreach (DataRow dr in rowDeleteDB)
                    {
                        int pklength = ids.RealDataSet.Tables[0].PrimaryKey.Length;
                        if (pklength > 0)
                        {
                            object[] values = new object[pklength];
                            for (int i = 0; i < pklength; i++)
                            {
                                values[i] = dr[ids.RealDataSet.Tables[0].PrimaryKey[i]];
                            }
                            DataRow filerow = this.RealDataSet.Tables[0].Rows.Find(values);
                            if (filerow != null)
                            {
                                this.RealDataSet.Tables[0].Rows.Remove(filerow);
                            }
                        }
                        ids.RealDataSet.Tables[0].Rows.Remove(dr);
                    }
                }
                this.RealDataSet.Merge(ids.RealDataSet);

                //save
                Save();
            }
            LastDateTime = datetime.ToString("yyyyMMddHHmmss", new System.Globalization.CultureInfo("en-us"));
        }
Beispiel #4
0
 private void tbTableName_TextChanged(object sender, EventArgs e)
 {
     if (radioButtonEntity.Checked)
     {
         if (tbComboEntityName.Text != String.Empty)
         {
             Dictionary<string, object> htFields = WzdUtils.GetFieldsByEntityName(FClientData.AssemblyName, FClientData.CommandName, this.tbComboEntityName.Text);
             cbDataTextField.Items.Clear();
             cbDataValueField.Items.Clear();
             foreach (var field in htFields)
             {
                 cbDataTextField.Items.Add(field.Key.ToString());
                 cbDataValueField.Items.Add(field.Key.ToString());
             }
         }
         else
         {
             cbDataTextField.Items.Clear();
             cbDataValueField.Items.Clear();
         }
     }
     else if (radioButtonInfoCommand.Checked)
     {
         if (tbComboEntityName.Text != String.Empty)
         {
             InfoDataSet ds = new InfoDataSet();
             ds.SetWizardDesignMode(true);
             ds.RemoteName = tbComboRemoteName.Text;
             ds.ClearWhere();
             ds.SetWhere("1=0");
             ds.Active = true;
             cbDataTextField.Items.Clear();
             cbDataValueField.Items.Clear();
             foreach (DataColumn field in ds.GetRealDataSet().Tables[0].Columns)
             {
                 cbDataTextField.Items.Add(field.ColumnName);
                 cbDataValueField.Items.Add(field.ColumnName);
             }
         }
         else
         {
             cbDataTextField.Items.Clear();
             cbDataValueField.Items.Clear();
         }
     }
 }
Beispiel #5
0
        public void Refresh()
        {
            if (this.Count == 0)
            {
                return;
            }
            DataRow xRow = ((DataRowView)Current).Row;
            if (DataSource is IInfoDataSet)
            {
                IInfoDataSet ds = (IInfoDataSet)DataSource;
                if (xRow != null)
                {
                    if (null != ds.RealDataSet.Tables[0].PrimaryKey)
                    {
                        string strModuleName = ds.RemoteName.Substring(0, (ds.RemoteName.IndexOf('.')));
                        string strTableName = ds.RemoteName.Substring((ds.RemoteName.IndexOf('.') + 1));
                        string sqlcmd = CliUtils.GetSqlCommandText(strModuleName, strTableName, CliUtils.fCurrentProject);

                        string wherePart = "";
                        DataColumn[] mydc = (DataColumn[])(ds.RealDataSet.Tables[0].PrimaryKey);
                        DataColumnCollection mydc2 = ds.RealDataSet.Tables[0].Columns;
                        object[] mykeys = new object[mydc.Length];
                        ClientType ct = CliUtils.GetDataBaseType();
                        for (int ix = 0; ix < mydc.Length; ix++)
                        {
                            mykeys[ix] = xRow[mydc[ix]];

                            // Create sql where part.
                            if (wherePart.Length != 0)
                                wherePart += " and ";

                            wherePart += CliUtils.GetTableNameForColumn(sqlcmd, ((DataColumn)mydc[ix]).ColumnName) + " = "
                                + string.Format(DBUtils.GetWhereFormat(((DataColumn)mydc[ix]).DataType, ct, OdbcDBType.None, 0)
                            ,DBUtils.GetWhereValue(((DataColumn)mydc[ix]).DataType, xRow[mydc[ix]]));

                        }

                        IInfoDataSet ds2 = new InfoDataSet();
                        ds2.RemoteName = ds.RemoteName;
                        ds2.SetWhere(wherePart);
                        if (ds2 == null || ds2.RealDataSet == null || ds2.RealDataSet.Tables.Count == 0 ||
                            ds2.RealDataSet.Tables[0].Rows.Count == 0)
                        {
                            bool allowD = this.AllowDelete;
                            this.AllowDelete = true;
                            this.RemoveCurrent();
                            this.AllowDelete = allowD;
                            ds.RealDataSet.AcceptChanges();
                            return;
                        }
                        if (this.Container != null)
                        {
                            RegisterListEvent(false);
                            foreach (Component cp in this.Container.Components)
                            {
                                if (cp is InfoBindingSource && (cp as InfoBindingSource).DataSource == this)
                                {
                                    bool allowD = (cp as InfoBindingSource).AllowDelete;
                                    (cp as InfoBindingSource).AllowDelete = true;
                                    int count = (cp as InfoBindingSource).Count;
                                    for (int i = 0; i < count; i++)
                                    {
                                        (cp as InfoBindingSource).RemoveAt(0);
                                    }
                                    (cp as InfoBindingSource).AllowDelete = allowD;
                                }
                            }
                            RegisterListEvent(true);

                            ds.RealDataSet.AcceptChanges();
                        }
                        xRow = ds.RealDataSet.Tables[0].Rows.Find(mykeys);

                        if (this.ServerModifyCache)
                        {
                            this.CancelPositionChanged = true;
                            this.SuspendBinding();
                        }
                        // 同步Row。
                        SyncRow(mydc2, xRow, ds2.RealDataSet.Tables[0].Rows[0]);
                        if (this.ServerModifyCache)
                        {
                            this.CancelPositionChanged = false;
                            this.ResumeBinding();
                        }

                        //处理所有的Detail
                        for (int i = 1; i < ds.RealDataSet.Tables.Count; i++)
                        {
                            ds.RealDataSet.Tables[i].Merge(ds2.RealDataSet.Tables[i]);
                        }
                        ds.RealDataSet.AcceptChanges();

                        DataRowView drv = (DataRowView)Current;
                        DataView dv = drv.DataView;
                        for (int i = 0; i < dv.Count; i++)
                        {
                            if (dv[i].Row == xRow)
                            {
                                Position = i;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    ds.Active = false;
                    ds.Active = true;
                }
            }
        }