Exemple #1
0
        public int Update(VendorQuery model, List<TableChangeLog> list)
        {
            UserHistoryDao _userhistoryDao = new UserHistoryDao(connStr);
            SerialDao _serialDao = new SerialDao(connStr);
            model.Replace4MySQL();
            int i = 0;

            try
            {
                ArrayList _list = new ArrayList();

                model.content = _vendorDao.ReturnHistoryCon(model).ToString();

                #region 處理vendor表
                _list.Add(_vendorDao.UpdateVendor(model));

                #endregion
                #region 處理userhistory表
                _list.Add(_userhistoryDao.Save(model));

                #endregion

                #region 處理table_change_log 記錄供應商資料異動
                //if (!string.IsNullOrEmpty(update_log))
                //{
                //    update_log = update_log.TrimEnd('#');//去掉最後一個#
                //    string[] arr_log = update_log.Split('#');//分離每條記錄
                //    foreach (string item in arr_log)
                //    {
                //        TableChangeLogDao _logDao = new TableChangeLogDao(connStr);
                //        string[] arr_col = item.Split(':');
                //        TableChangeLog tcl = new TableChangeLog();
                //        tcl.change_table = "vendor";
                //        tcl.change_field = arr_col[0].ToString();
                //        tcl.field_ch_name = arr_col[3].ToString();
                //        tcl.create_time = model.created;
                //        tcl.create_user = (int)model.kuser_id;
                //        tcl.pk_id = (int)model.vendor_id;
                //        tcl.old_value = arr_col[1].ToString();
                //        tcl.new_value = arr_col[2].ToString();
                //        tcl.user_type = model.user_type;
                //        _list.Add(_logDao.insert(tcl));
                //    }
                //}
                if (list != null)
                {
                    foreach (TableChangeLog t in list)
                    {
                        TableChangeLogDao _logDao = new TableChangeLogDao(connStr);
                        t.change_table = "vendor";
                        t.create_time = model.created;
                        t.create_user = (int)model.kuser_id;
                        t.pk_id = (int)model.vendor_id;
                        t.user_type = model.user_type;
                        _list.Add(_logDao.insert(t));
                    }
                }
                #endregion

                if (_mysqlDao.ExcuteSqls(_list))
                {
                    i = 1;
                }
                return i;
            }
            catch (Exception ex)
            {

                throw new Exception("VendorDao-->Update-->" + ex.Message, ex);
            }
        }
Exemple #2
0
        public int SaveUserPhone(Model.Query.UserQuery uQuery)
        {
            _userhistoryDao = new UserHistoryDao(connStr);
            _smsdao = new SmsDao(connStr);
            _serialDao = new SerialDao(connStr);
            Serial serial = new Serial();
            uQuery.Replace4MySQL();
            int i = 0;
            MySqlCommand mySqlCmd = new MySqlCommand();
            MySqlConnection mySqlConn = new MySqlConnection(connStr);
            try
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Closed)
                {
                    mySqlConn.Open();
                }
                mySqlCmd.Connection = mySqlConn;
                mySqlCmd.Transaction = mySqlConn.BeginTransaction();

                mySqlCmd.CommandType = System.Data.CommandType.Text;

                #region 處理serial表數據


                mySqlCmd.CommandText = _serialDao.Update(22);//22電話會員
                serial = _serialDao.GetSerialById(22);
                uQuery.user_id = Convert.ToUInt32(serial.Serial_Value) + 1;

                #endregion

                #region 處理user 和user_history數據

                mySqlCmd.CommandText = Save(uQuery);
                mySqlCmd.CommandText += _userhistoryDao.Save(uQuery);

                #endregion

                #region 處理sms表
                Sms smsModel = new Sms();
                smsModel.type = 9;
                smsModel.mobile = uQuery.user_mobile;
                smsModel.subject = "電話會員";
                smsModel.content = "感謝您選擇成為吉甲地市集電話會員,未來我們將透過簡訊提供商品優惠。日後若有電話訂購服務之需求,可撥打專線(02)2783-4995,謝謝。";
                smsModel.send = uQuery.send_sms_ad == true ? 1 : 0;
                smsModel.created = uQuery.created;
                smsModel.modified = uQuery.created;
                smsModel.estimated_send_time = uQuery.created;
                mySqlCmd.CommandText += _smsdao.SaveSms(smsModel);

                #endregion

                i += mySqlCmd.ExecuteNonQuery();
                //全部执行成功以后,对serial表的serial_value的值進行變更
                if (i == 3)
                {
                    serial.Serial_Value = serial.Serial_Value + 1;
                    int j = _serialDao.Update(serial);
                }
                mySqlCmd.Transaction.Commit();
            }
            catch (Exception ex)
            {
                mySqlCmd.Transaction.Rollback();
                throw new Exception("UsersDao-->Save-->" + ex.Message + mySqlCmd.CommandText.ToString(), ex);
            }
            finally
            {
                if (mySqlConn != null && mySqlConn.State == System.Data.ConnectionState.Open)
                {
                    mySqlConn.Close();
                }
            }
            return i;
        }