~$taset和XML和bingdingsource,ILIST的一些关系和转换。(新手整理些遇到的问题)

4 篇文章 0 订阅

  1.1 DataSetds = new DataSet();

            if(File.Exists("DefaultPrint.xml"))

            {  //存在文件

                ds.ReadXml("DefaultPrint.xml");

            }

            else

            {

                //不存在文件

                //File.Create("DefaultPrint.xml");//创建该文件

                System.IO.FileStream stream = File.Create("DefaultPrint.xml ");

 

                stream.Close();

                ds.WriteXml("DefaultPrint.xml");

 

                ds.ReadXml("DefaultPrint.xml");

            }

1.2.DataSet ds = new DataSet();

           //System.IO.Stream stream =System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DefaultPrint.xml");

            ds.ReadXml("DefaultPrint.xml");

            ds.Tables[0].Rows.Clear();

            int i;

                       for ( i =0;(listBox2.Items.Count) - 1 >=i; i++)

            {

                

                 DataRow dr =ds.Tables["DefaultPrint"].NewRow();

                 dr["prid"] = i + 1;

                 dr["tempplate"] = listBox2.Items[i].ToString();

                 dr["template_type"]= "普通快递";

                 dr["print_name"] ="";

                 dr["loglistcompany"]= "";

                 ds.Tables[0].Rows.Add(dr);

            }

            for (int j =0; (listBox3.Items.Count)- 1 >= j;j++)

            {

                 DataRow dr =ds.Tables["DefaultPrint"].NewRow();

                 dr["prid"] = i +j+1;

                 dr["tempplate"] =listBox3.Items[j].ToString();

                dr["template_type"]= "到付快递";

                 dr["print_name"] ="";

                 dr["loglistcompany"]= "";

                ds.Tables[0].Rows.Add(dr);

            }

            ds.WriteXml("DefaultPrint.xml");

2. foreach(DataRow r in ds.Tables[0].Rows)

           {

               if (r[2].ToString() =="普通快递")

                   listBox1.Items.Add(r[1].ToString());

                else if (r[2].ToString() =="到付快递")

                    listBox2.Items.Add(r[1].ToString());

}

3.           

 DataSet ds= new DataSet();

 ds.ReadXml("DefaultPrint.xml");

 bindingSource1.DataSource =ds.Tables[0];

bindingSource1.EndEdit();//会把更新提交到内存中的对象或对象列表(如DataSet)

4

DataSet ds = new DataSet();

IList<TB_ORDER> tboder =serviceLocator.GetService<IORDERBLL>().RetrieveAll();

            ds = ConvertToDataSet<TB_ORDER>(tboder); /// Ilist<T> 转换成 DataSet

        /// </summary>

        /// <paramname="list"></param>

        /// <returns></returns>

        publicstatic DataSetConvertToDataSet<T>(IList<T>i_objlist)

        {

            if(i_objlist == null || i_objlist.Count <= 0)

            {

                return null;

            }

            DataSetds = new DataSet();

            DataTabledt = new DataTable(typeof(T).Name);

            DataColumncolumn;

            DataRowrow;

            System.Reflection.PropertyInfo[] myPropertyInfo = typeof(T).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            foreach(T t in i_objlist)

            {

                if (t == null)

                {

                    continue;

                }

                row = dt.NewRow();

                for (int i = 0, j =myPropertyInfo.Length; i < j; i++)

                {

                   System.Reflection.PropertyInfo pi =myPropertyInfo[i];

                    stringname = pi.Name;

                    if (dt.Columns[name] == null)

                    {

                        column = new DataColumn(name,pi.PropertyType);

                       dt.Columns.Add(column);

                    }

                    row[name] =pi.GetValue(t, null);

                }

                dt.Rows.Add(row);

            }

            ds.Tables.Add(dt);

            returnds;

        }

 

 

5

//打印按钮

        [DllImport("winspool.drv")]

        publicstatic extern bool SetDefaultPrinter(stringName);

        privatevoid btn_Print_Click(objectsender, EventArgs e)

        {

      

            DataSetds = new DataSet();

            IList<TB_REPORT_TEMPLATE> list1 =serviceLocator.GetService<IREPORT_TEMPLATE>().RetrieveAll();

            IList<TB_ORDER> tboder =serviceLocator.GetService<IORDERBLL>().RetrieveAll();

            ds =ConvertToDataSet<TB_ORDER>(tboder);

            DataSetds1=new DataSet();

            ds1.ReadXml("DefaultPrint.xml");

            if(lbx_CommonDel.Enabled == true)

            {

 

                for (int i = 0; i< list1.Count; i++)

                {

                   if (list1[i].TYPE_NAME.ToString() ==lbx_CommonDel.SelectedItem.ToString())

                   {

                      foreach (DataRow r inds1.Tables[0].Rows)

                      {

                         if (r[1].ToString() ==lbx_CommonDel.SelectedItem.ToString())

                           {

                               if (r[3].ToString() !="")

                               {

 

                                   string str = list1[i].PATH.ToString();

                                  SetDefaultPrinter(r[3].ToString());

                                   XtraReport xr = newXtraReport();

                                   xr.DataSource = ds;

                                  xr.LoadLayout(str);

                                  xr.Print();

                                   break;

                               }

                               else

                               {

                                   MessageBox.Show("必须先给该模板设置默认打印机");

                                   CommonWorkItem<LockPrintView>workitem = workItem.Items.AddNew<CommonWorkItem<LockPrintView>>();

 

                                   WindowSmartPartInfosmartPartInfo = new WindowSmartPartInfo();

                                  smartPartInfo.Width = 580;

                                  smartPartInfo.Height = 455;

                                  smartPartInfo.Location = newSystem.Drawing.Point(150, 150);

                                  workitem.Space = workItem.Workspaces["DialogWorkspace"];

                                  workitem.Show(smartPartInfo);

 

                                   this.Dispose();

                                   break;

                               }

                            }

                         }

                      }

 

                   }

            }

            else

            {

                for (int i = 0; i< list1.Count; i++)

                {

                    if (list1[i].TYPE_NAME.ToString() ==lbx_ArrPayDel.SelectedItem.ToString())

                    {

                        foreach (DataRow rin ds1.Tables[0].Rows)

                        {

                            if(r[1].ToString() == lbx_ArrPayDel.SelectedItem.ToString())

                            {

                                if (r[3].ToString() != "")

                                {

 

                                    string str = list1[i].PATH.ToString();

                                   SetDefaultPrinter(r[3].ToString());

                                    XtraReport xr = newXtraReport();

                                   xr.DataSource = ds;

                                   xr.LoadLayout(str);

                                   xr.Print();

                                    break;

                                }

                                else

                                {

                                    MessageBox.Show("必须先给该模板设置默认打印机");

                                    CommonWorkItem<LockPrintView>workitem = workItem.Items.AddNew<CommonWorkItem<LockPrintView>>();

 

                                    WindowSmartPartInfo smartPartInfo = new WindowSmartPartInfo();

                                    smartPartInfo.Width= 580;

                                   smartPartInfo.Height = 455;

                                   smartPartInfo.Location = newSystem.Drawing.Point(150, 150);

                                   workitem.Space = workItem.Workspaces["DialogWorkspace"];

                                   workitem.Show(smartPartInfo);

                                    this.Dispose();

                                    break;

                                }

                            }

                        }

                    }

 

                }

 

            }

            this.Dispose();

        }

       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值