示例#1
0
        public void Bind()
        {
            iden_lab.Text = iden.ToString();
            string msg = Main.Menu.First(x => x.id == iden).name.Replace("数据映射", "");

            switch (BinType)
            {
            case 0: groupBox1.Text = "全部数据(" + msg + ")"; break;

            case 1: groupBox1.Text = "数据标准化(" + msg + ")"; break;
            }
            //if (BinType != 1)
            //{
            dataGridViewX1.Columns["Column2"].Visible = false;
            dataGridViewX1.Columns["Column1"].Visible = false;
            dataGridViewX1.Columns["linkid"].Visible  = false;
            //}
            soso.syntoolSoapClient bll = new soso.syntoolSoapClient();
            var li = bll.GetMaptoolDataList(PageSize, PageIndex, order, orderField, like, whereField, sqlext, BinType, Login.authKey, this.iden);

            if (li != null)
            {
                var dt = li.Tables[0];
                dt.Columns.Add("StockTypes", typeof(string));
                dt.Columns.Add("PriceTypes", typeof(string));

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["StockType"] != System.DBNull.Value)
                    {
                        switch (Convert.ToInt32(dt.Rows[i]["StockType"]))
                        {
                        case 1:
                            dt.Rows[i]["StockTypes"] = GetUnit(1);
                            break;

                        case 2:
                            dt.Rows[i]["StockTypes"] = GetUnit(2);
                            break;

                        case 3:
                            dt.Rows[i]["StockTypes"] = GetUnit(3);
                            break;
                        }
                    }
                    if (dt.Rows[i]["PriceType"] != System.DBNull.Value)
                    {
                        switch (Convert.ToInt32(dt.Rows[i]["PriceType"]))
                        {
                        case 1:
                            dt.Rows[i]["PriceTypes"] = GetUnit(1);
                            break;

                        case 2:
                            dt.Rows[i]["PriceTypes"] = GetUnit(2);
                            break;

                        case 3:
                            dt.Rows[i]["PriceTypes"] = GetUnit(3);
                            break;
                        }
                    }

                    #region 动态添加价格类型
                    string    ID         = dt.Rows[i]["ID"].ToString();
                    DataTable PriceTable = bll.GetPriceByID(ID);
                    if (PriceTable != null && PriceTable.Rows.Count > 0)
                    {
                        foreach (DataRow dr in PriceTable.Rows)
                        {
                            string  tempcategory = dr["category"] == null ? string.Empty : dr["category"].ToString();
                            decimal tempprice    = dr["price_n"] == null ? 0 : Convert.ToDecimal(dr["price_n"]);
                            //添加新列
                            if (!dt.Columns.Contains(tempcategory))
                            {
                                dt.Columns.Add(tempcategory, typeof(string));
                                if (!dataGridViewX1.Columns.Contains(tempcategory))
                                {
                                    dataGridViewX1.Columns.Insert(12, new DataGridViewTextBoxColumn()
                                    {
                                        HeaderText       = tempcategory,
                                        DataPropertyName = tempcategory,
                                        Name             = tempcategory
                                    });
                                }
                            }
                            dt.Rows[i][tempcategory] = tempprice;
                        }
                    }
                    #endregion
                }
                dataGridViewX1.DataSource = dt;
                recordCount = int.Parse(li.Tables[1].Rows[0]["recordCount"].ToString());
                pageCount   = int.Parse(li.Tables[1].Rows[0]["pageCount"].ToString());
                paginger();
                labelX1.Text = string.Format("共{0}条记录", recordCount);
            }
            else
            {
                MessageBox.Show("您的登陆状态已经失效,请关闭后重新登陆!", "操作失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }