using LYFZ.WinAPI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace LYFZ.ERPCloudClient
{
public partial class frmAdd_OR_Edit_Enterprise : LYFZ.ComponentLibrary.BaseContentsFormMain
{
public frmAdd_OR_Edit_Enterprise()
{
InitializeComponent();
this.Shown += frmAdd_OR_Edit_Enterprise_Shown;
this.btnDetermine.Click += btnDetermine_Click;
this.btnExit.Click += btnExit_Click;
this.cbxServerList.SelectedValueChanged += cbxServerList_SelectedValueChanged;
this.gbtnCopyEid.Click += gbtnCopyEid_Click;
this.gbtnCopyCode.Click += gbtnCopyCode_Click;
this.gbtnCopyAppZhuche.Click += gbtnCopyAppZhuche_Click;
this.gbtnCopyAll.Click += gbtnCopyAll_Click;
if (frmMain.LoginUser.QuanXianPeiZhi == "2")
{
this.btnDetermine.Enabled = false;
}
}
void gbtnCopyAll_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject("客户(企业)名称:"+this.txtEnterpriseName.Text.Trim()+"\r\n"
+"企业ID:" + this.txtEnterpriseID.Text+"\r\n"
+ "安装验证码:" + this.txtInstallationCode.Text+"\r\n"
+ "APP注册码:" + this.txtWebAppLicense.Text);
}
///
/// 复制APP注册码
///
///
///
void gbtnCopyAppZhuche_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
+ "APP注册码:" + this.txtWebAppLicense.Text);
}
///
/// 复制安装验证码
///
///
///
void gbtnCopyCode_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
+ "安装验证码:" + this.txtInstallationCode.Text);
}
///
/// 复制企业ID
///
///
///
void gbtnCopyEid_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject("客户(企业)名称:" + this.txtEnterpriseName.Text.Trim() + "\r\n"
+ "企业ID:" + this.txtEnterpriseID.Text);
}
void cbxServerList_SelectedValueChanged(object sender, EventArgs e)
{
if (this.cbxServerList.SelectedItem != null)
{
LYFZ.CloudServerData.Model.CloudServerCollection serverModel = (LYFZ.CloudServerData.Model.CloudServerCollection)this.cbxServerList.SelectedItem;
this.txtDomainName.Text = serverModel.DomainName;
this.txtWebAppLicense.Text = GetWebAppLicense(serverModel, this.txtEnterpriseID.Text,this.txtInstallationCode.Text.Trim());
if (String.IsNullOrEmpty(serverModel.FrpConfig))
{
MessageBoxCustom.Show("您选择的服务器配不正确,请重新配置服务器后重试");
}
}
}
///
/// 获取WebApp注册码
///
///
///
string GetWebAppLicense(LYFZ.CloudServerData.Model.CloudServerCollection server, string _EnterpriseID, string _InstallationCode)
{
string retLicense = "";
if (!String.IsNullOrEmpty(server.FrpConfig))
{
LYFZ.CloudServerData.Model.FRPConfig frpModel = LYFZ.CloudServerData.Model.FRPConfig.JsonDeserializeObject(server.FrpConfig);
dynamic licenseData = new
{
Server_addr = frpModel.Server_addr,
Server_port = frpModel.Server_port,
Privilege_token = frpModel.Privilege_token,
Vhost_http_port = frpModel.Vhost_http_port,
IISWebPort = frpModel.IISWebPort,
EnterpriseID = _EnterpriseID,
ErpServerPort = server.SeverPort,
ErpServerIP=server.DataBaseServerIP,
InstallationCode=_InstallationCode,
ApplyDateTime=DateTime.Now.ToYYYY_MM_dd_HH_mm_ss()
};
retLicense = Newtonsoft.Json.JsonConvert.SerializeObject(licenseData);
}
return LYFZ.WinAPI.SDKSecurity.EncryptDES(retLicense,"lyfz@liu");
}
void btnExit_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
void btnDetermine_Click(object sender, EventArgs e)
{
this.EnterpriseModel.EnterpriseID=this.txtEnterpriseID.Text.Trim();
this.EnterpriseModel.EnterpriseName = this.txtEnterpriseName.Text.Trim();
this.EnterpriseModel.ContactPerson = this.txtContactPerson.Text.Trim();
this.EnterpriseModel.Phone = this.txtPhone.Text.Trim();
this.EnterpriseModel.InstallationCode = this.txtInstallationCode.Text.Trim();
this.EnterpriseModel.EffectiveTime = this.dateTimeEffectiveTime.Value.ToJavaScriptTimeStamp();
this.EnterpriseModel.WebInterfaceAddress = this.txtWebUrl.Text.Trim();
this.EnterpriseModel.Address = this.txtAdderss.Text.Trim();
this.EnterpriseModel.Remarks = this.txtRemarks.Text.Trim();
this.EnterpriseModel.AnnualFee = this.nuMoney.Value;
this.EnterpriseModel.OssCloudDisk=Convert.ToInt32(this.nuOssCloudDisk.Value);
this.EnterpriseModel.ClientAnnualFee = this.nudClientValidity.Value;
if (this.cbxServerList.SelectedItem != null)
{
this.EnterpriseModel.CloudServerID = ((LYFZ.CloudServerData.Model.CloudServerCollection)this.cbxServerList.SelectedItem).ID;
}
else {
MessageBoxCustom.Show("请选择服务器");
return;
}
if (String.IsNullOrEmpty(this.EnterpriseModel.EnterpriseID.Trim()))
{
MessageBoxCustom.Show("企业ID不能为空");
return;
}
if (String.IsNullOrEmpty(this.EnterpriseModel.EnterpriseName.Trim()))
{
MessageBoxCustom.Show("企业名称不能为空");
return;
}
if (String.IsNullOrEmpty(this.EnterpriseModel.ContactPerson.Trim()))
{
MessageBoxCustom.Show("联系人不能为空");
return;
}
if (String.IsNullOrEmpty(this.EnterpriseModel.Phone.Trim()))
{
MessageBoxCustom.Show("联系电话不能为空");
return;
}
if (this.EnterpriseModel.Phone.Trim().Length<7)
{
MessageBoxCustom.Show("联系电话不能小于7位");
return;
}
var featuresData = new
{
MoveAPP = new
{
name = "手机APP",
value = this.chkMoveAPP.Checked ? 1 : 0
},
CloudDatabase = new
{
name = "托管数据库",
value = this.chkCloudDatabase.Checked ? 1 : 0
},
OssCloudDisk = new
{
name = "OSS云盘",
value = this.chkOssCloudDisk.Checked ? 1 : 0
},
ClientDisk = new
{
name = "客片下载",
value = this.chkClientDisk.Checked ? 1 : 0
}
};
this.EnterpriseModel.Features = Newtonsoft.Json.JsonConvert.SerializeObject(featuresData);
bool isSuccess = false;
LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
{
backgroundWorker.ReportProgress(0, "正在提交客户资料...");
try
{
HPSocketCS.Extended.ReturnData returnData = LYFZ.CloudServerData.ClientDataRequestProcess.RequestQueryAddOrEditEnterprise(frmMain.TcpClient.Client, this.EnterpriseModel);
if (returnData.ReturnStatus)
{
isSuccess = returnData.DataByteToModelObject();
if (!isSuccess)
{
MessageBoxCustom.Show("提交客户资料失败,请与管理员联系", backgroundWorker: backgroundWorker);
}
else
{
dynamic jsonData = new ExpandoObject();
jsonData.entId= this.EnterpriseModel.EnterpriseID.Trim();
jsonData.status = this.chkClientDisk.Checked ? 1 : 0;
jsonData.entName=this.EnterpriseModel.EnterpriseName.Trim();
jsonData.linker= this.EnterpriseModel.ContactPerson;
jsonData.linkTele = this.EnterpriseModel.Phone;
jsonData.validityTime = this.dateTimeEffectiveTime.Value;
jsonData.serviceCharge = this.nudClientValidity.Value;
string txt = HttpClientHelper.PostResponse("http://p.lyfz.net/api/Systems.ashx/CusRegisterByApp", Newtonsoft.Json.JsonConvert.SerializeObject(jsonData));
dynamic dyObjJson = Newtonsoft.Json.JsonConvert.DeserializeObject(txt);
if(dyObjJson.code!=200)
{
MessageBoxCustom.Show("客片管理操作失败:" + dyObjJson.data, backgroundWorker: backgroundWorker);
}
}
}
else
{
MessageBoxCustom.Show("提交客户资料:" + returnData.ReturnMessage, backgroundWorker: backgroundWorker);
}
}
catch (Exception ex)
{
MessageBoxCustom.Show("提交客户资料出错:" + ex.Message, backgroundWorker: backgroundWorker);
}
});
if (isSuccess)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
void BindServerList()
{
if (frmCloudServerCollection.CloudServerCollectionList.Count <= 0)
{
frmCloudServerCollection.LoadCloudServerCollection();
}
this.cbxServerList.Items.Clear();
// this.cbxServerList.Items.Add(new LYFZ.CloudServerData.Model.CloudServerCollection("店内服务器"));
foreach (LYFZ.CloudServerData.Model.CloudServerCollection serverCollectionModel in frmCloudServerCollection.CloudServerCollectionList)
{
this.cbxServerList.Items.Add(serverCollectionModel);
}
// this.cbxServerList.SelectedIndex = 0;
}
void frmAdd_OR_Edit_Enterprise_Shown(object sender, EventArgs e)
{
BindServerList();
if (EnterpriseModel.ID > 0)
{
this.txtEnterpriseID.ReadOnly = true;
this.txtEnterpriseID.Text = this.EnterpriseModel.EnterpriseID.Trim();
this.txtEnterpriseName.Text = this.EnterpriseModel.EnterpriseName.Trim();
this.txtContactPerson.Text = this.EnterpriseModel.ContactPerson;
this.txtPhone.Text = this.EnterpriseModel.Phone;
this.txtInstallationCode.Text = this.EnterpriseModel.InstallationCode.Trim();
this.txtWebUrl.Text = this.EnterpriseModel.WebInterfaceAddress.Trim();
this.dateTimeEffectiveTime.Value = this.EnterpriseModel.EffectiveTime.JavaScriptTimeStampToDateTime();
this.txtAdderss.Text = this.EnterpriseModel.Address;
this.txtRemarks.Text = this.EnterpriseModel.Remarks;
this.nuMoney.Value = this.EnterpriseModel.AnnualFee;
this.nudClientValidity.Value = this.EnterpriseModel.ClientAnnualFee;
if (!String.IsNullOrEmpty(this.EnterpriseModel.Features.Trim()))
{
dynamic featuresData = Newtonsoft.Json.JsonConvert.DeserializeObject(this.EnterpriseModel.Features);
this.chkMoveAPP.Checked = featuresData.MoveAPP.value == 1 ? true : false;
this.chkCloudDatabase.Checked = featuresData.CloudDatabase.value == 1 ? true : false;
if (featuresData.OssCloudDisk == null)
{
this.chkOssCloudDisk.Checked = true;
}
else {
this.chkOssCloudDisk.Checked = featuresData.OssCloudDisk.value == 1 ? true : false;
}
if (featuresData.ClientDisk == null)
{
this.chkClientDisk.Checked = false;
}
else
{
this.chkClientDisk.Checked = featuresData.ClientDisk.value == 1 ? true : false;
}
}
else
{
this.chkMoveAPP.Checked = false;
this.chkCloudDatabase.Checked = false;
this.chkOssCloudDisk.Checked = true;
this.chkClientDisk.Checked = false;
}
this.nuOssCloudDisk.Value = this.EnterpriseModel.OssCloudDisk;
foreach (LYFZ.CloudServerData.Model.CloudServerCollection serverCollectionModel in this.cbxServerList.Items)
{
if (serverCollectionModel.ID == EnterpriseModel.CloudServerID)
{
this.cbxServerList.SelectedItem = serverCollectionModel;
}
}
}
else
{
this.txtEnterpriseID.Text = LYFZ.CloudServerData.DAL.Enterprise.GetNewEnterpriseID();
this.txtInstallationCode.Text = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(this.txtEnterpriseID.Text.Trim() + SDateTime.Now.ToJavaScriptTimeStamp().ToString());
this.dateTimeEffectiveTime.Value = SDateTime.Now.AddYears(1);
}
}
LYFZ.CloudServerData.Model.Enterprise _EnterpriseModel = new CloudServerData.Model.Enterprise();
///
/// 客户实体
///
public LYFZ.CloudServerData.Model.Enterprise EnterpriseModel
{
get { return _EnterpriseModel; }
set { _EnterpriseModel = value; }
}
}
}