コード例 #1
0
 protected override void Loading()
 {
     if (!IsAdd)
     {
         var obj = BaseInfoCard.FindById(long.Parse(ItemID));
         FrmAddEditBindComboBoxText.BindObjectToControls(obj, tabPage1);
         if (obj.BaseInfoMember != null)
         {
             ctMemberCardNumber.Text = obj.BaseInfoMember.CardNumber;
         }
     }
     else
     {
         ctCountLeft.Value  = 10;
         ctJoinedDate.Value = DateTime.Now;
     }
 }
コード例 #2
0
 protected override void Saving()
 {
     if (IsAdd)
     {
         if (MemberId == -1)
         {
             var obj = BaseInfoCard.New;
             FrmAddEditBindComboBoxText.BindControlsToObject(obj, tabPage1);
             obj.OptrType = UserStatics.OptrType;
             obj.Save();
         }
         else
         {
             var member = BaseInfoMember.FindById(MemberId);
             var obj    = BaseInfoCard.New;
             FrmAddEditBindComboBoxText.BindControlsToObject(obj, tabPage1);
             obj.OptrType = UserStatics.OptrType;
             obj.Save();
             member.BaseInfoCards.Add(obj);
             member.Save();
         }
     }
     else
     {
         if (MemberId == -1)
         {
             var obj = BaseInfoCard.FindById(long.Parse(ItemID));
             FrmAddEditBindComboBoxText.BindControlsToObject(obj, tabPage1);
             obj.OptrType = UserStatics.OptrType;
             obj.Save();
         }
         else
         {
             var member = BaseInfoMember.FindById(MemberId);
             var obj    = BaseInfoCard.FindById(long.Parse(ItemID));
             FrmAddEditBindComboBoxText.BindControlsToObject(obj, tabPage1);
             obj.OptrType = UserStatics.OptrType;
             obj.Save();
             member.BaseInfoCards.Add(obj);
             member.Save();
         }
     }
 }
コード例 #3
0
        public void ImportToAccess()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                DataSet ds      = new DataSet();
                string  strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + ofd.FileName + ";" +
                                  "Extended Properties=Excel 8.0;";
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                string           strExcel  = "";
                OleDbDataAdapter myCommand = null;
                strExcel  = string.Format("select * from [{0}$]", "Sheet1"); //Sheet1为excel中工作薄
                myCommand = new OleDbDataAdapter(strExcel, strConn);
                myCommand.Fill(ds, "Sheet1");
                DataTable dt = ds.Tables["Sheet1"];

                Encoding gb2312 = Encoding.GetEncoding("GB2312");
                for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
                {
                    BaseInfoCard bic = BaseInfoCard.New;
                    bic.JoinedDate = (DateTime)dt.Rows[iRow][0];
                    bic.CardNumber = dt.Rows[iRow][1].ToString();
                    bic.ChildName  = dt.Rows[iRow][2].ToString();
                    bic.Mobile     = dt.Rows[iRow][4].ToString();
                    bic.CardType   = dt.Rows[iRow][5].ToString();
                    bic.CountLeft  = decimal.Parse(dt.Rows[iRow][6].ToString());

                    DateTime dtime = (DateTime)dt.Rows[iRow][0];
                    bic.ExpirationDate = dtime.AddYears(1);

                    bic.Remark     = dt.Rows[iRow][8].ToString();
                    bic.CardStatus = 1;
                    bic.PinYin     = PinYinTransfer.GetInitials(bic.ChildName, gb2312);
                    bic.SavedOn    = DateTime.Now;
                    bic.OptrType   = UserStatics.OptrType;
                    bic.Save();
                }
            }
        }