You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

136 lines
5.6 KiB

using Newtonsoft.Json;
using NFine.Code;
using NFine.Data.Extensions;
using NFine.Domain._03_Entity.SRM;
using NFine.Repository;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NFine.Application.SRM
{
public class PurchugApp : RepositoryFactory<ICSPURCHUG>
{
public void SubmitPURCHUGCODE(string queryJson)
{
try
{
DataTable dt = new DataTable();
List<DbParameter> parameter = new List<DbParameter>();
ICSPURCHUG[] list = JsonConvert.DeserializeObject<ICSPURCHUG[]>(queryJson);
string sql = string.Empty;
string connString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string UserCode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
if(list[0].Flag==0){
sql = "select * from ICSPURCHUG where PURCHUGCODE='" + list[0].PURCHUGCODE + "'";
dt = SqlCommandHelper.SQlReturnData(sql, cmd);
if (dt != null && dt.Rows.Count > 0)
{
throw new Exception("采购组织已存在");
}
}
foreach (var obj in list)
{
sql = @"IF NOT EXISTS(SELECT * FROM dbo.ICSPURCHUG WHERE PURCHUGCODE=@PURCHUGCODEOld and WorkPoint=@WorkPoint)
BEGIN
INSERT INTO dbo.ICSPURCHUG
(
PURCHUGCODE
,PURCHUGNAME
,PURCHUGCONECT
,WorkPoint )
VALUES
(
@PURCHUGCODE
,@PURCHUGNAME
,@PURCHUGCONECT
,@WorkPoint )
END
ELSE
BEGIN
UPDATE dbo.ICSPURCHUG SET
PURCHUGNAME=@PURCHUGNAME,
PURCHUGCONECT=@PURCHUGCONECT,
PURCHUGCODE=@PURCHUGCODE
WHERE PURCHUGCODE=@PURCHUGCODEOld
END";
SqlParameter[] sp_Detail = {
new SqlParameter("@PURCHUGCODE",obj.PURCHUGCODE),
new SqlParameter("@PURCHUGCODEOld",obj.PURCHUGCODEOld),
new SqlParameter("@PURCHUGNAME",obj.PURCHUGNAME),
new SqlParameter("@PURCHUGCONECT",obj.PURCHUGCONECT),
new SqlParameter("@WorkPoint",obj.WorkPoint),
};
SqlCommandHelper.CmdExecuteNonQuery(sql, sp_Detail, cmd);
}
cmd.Transaction.Commit();
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public DataRow GetPurchug(string PURCHUGCODE, string WorkPoint)
{
//string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
DataRow dr = null;
string sql = string.Empty;
try
{
sql = @"SELECT
PURCHUGCODE,
PURCHUGNAME,
PURCHUGCONECT,
WorkPoint
FROM ICSPURCHUG
WHERE PURCHUGCODE='" + PURCHUGCODE + "' and WorkPoint in ('" + WorkPoint + "')";
dr = SqlHelper.GetDataRowBySql(sql);
return dr;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public string DeletePurchug(string keyValue, string WorkPoint)
{
//string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
string msg = "";
WorkPoint = WorkPoint.Substring(1, WorkPoint.Length - 2);
keyValue = keyValue.Substring(1, keyValue.Length - 2);
string sql = string.Empty;
sql = string.Format(@"DELETE FROM dbo.ICSPURCHUG WHERE PURCHUGCODE IN ({0}) and WorkPoint IN ({1})", keyValue.TrimEnd(','), WorkPoint.TrimEnd(','));
SqlHelper.ExecuteNonQuery(sql);
return msg;
}
}
}