123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using SinoChemCommonUtilities;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Wayne.Lib.Log;
- namespace SinochemInternetPlusApp
- {
- // the sql command should macth the db schema in the target fusion
- class MultiFusionsSupport
- {
- private static SqlCommandUtility sourceSqlCmd;
- private static SqlCommandUtility targetSqlCmd;
- private static readonly bool supportMultiFusions = ConfigurationValues.SupportMultiFusions;
- static MultiFusionsSupport()
- {
- try
- {
- if (supportMultiFusions)
- {
- sourceSqlCmd = new SqlCommandUtility(App.AppSettings["AnotherPosDatabaseConnStr"]); // default to the conn string to current machine
- string anotherConnStr = App.AppSettings["AnotherPosDatabaseConnStr"];
- targetSqlCmd = new SqlCommandUtility(anotherConnStr); // conn string to another fusion
- }
- }
- catch (Exception ex)
- {
- }
- }
- public static bool CopyXiaofei2ToTargetFusion(int jihao, string liushuihao, DebugLogger debugLogger)
- {
- if (!supportMultiFusions)
- {
- return false;
- }
- try
- {
- string querySql = string.Format(" select * from xiaofei2 " +
- " where jihao={0} and liushuino='{1}' ",
- jihao, liushuihao);
- Xiaofei2Model xiaofei2Model = sourceSqlCmd.ReadData<Xiaofei2Model>(querySql, DbModelConstructors.ConstructXiaofei2Model);
- if (xiaofei2Model != null)
- {
- string insertSql = string.Format(" insert into xiaofei2 (jihao, youpin, qty, danjia, amount, xf_date, xf_time, liushuino, fzqty, fzamount) " +
- " values({0}, '{1}', {2}, {3}, {4}, '{5}', '{6}', '{7}', {8}, {9}) ",
- xiaofei2Model.jihao, xiaofei2Model.youpin, xiaofei2Model.qty, xiaofei2Model.danjia, xiaofei2Model.amount, xiaofei2Model.xf_date, xiaofei2Model.xf_time,
- xiaofei2Model.liushuino, xiaofei2Model.fzqty, xiaofei2Model.fzamount);
- targetSqlCmd.Insertdata(insertSql, false);
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- debugLogger.Add(ex);
- return false;
- }
- }
- public static bool UpdateJyInfoToTargetFusionWhenFuelingStarted(int jihao, DebugLogger debugLogger)
- {
- if (!supportMultiFusions)
- {
- return false;
- }
- try
- {
- string updateSql = string.Format(" update jy_info set [status]='{0}', qty=0, amount=0 " +
- " where jihao='{1}' ",
- 'B', jihao);
- targetSqlCmd.UpdateData(updateSql);
- return true;
- }
- catch (Exception ex)
- {
- debugLogger.Add(ex);
- return false;
- }
- }
- public static bool CopyJyInfoToTargetFusion(int jihao, DebugLogger debugLogger)
- {
- if (!supportMultiFusions)
- {
- return false;
- }
- try
- {
- string querySql = string.Format(" select * from jy_info " +
- " where jihao={0} ",
- jihao);
- JyInfoModel jyInfoModel = sourceSqlCmd.ReadData<JyInfoModel>(querySql, DbModelConstructors.ConstructJyInfoModel);
- if (jyInfoModel != null)
- {
- string updateSql = string.Format(" update jy_info set [status]='{0}', youpin=N'{1}', qty={2}, amount={3}, fzqty={4}, fzamount={5} " +
- " where jihao='{6}' ",
- jyInfoModel.status, jyInfoModel.youpin, jyInfoModel.qty, jyInfoModel.amount, jyInfoModel.fzqty, jyInfoModel.fzamount,
- jyInfoModel.jihao);
- targetSqlCmd.UpdateData(updateSql);
- return true;
- }
- else
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- debugLogger.Add(ex);
- return false;
- }
- }
- }
- }
|