本文整理汇总了C#中System.Factory.GetByPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.GetByPrimaryKey方法的具体用法?C# Factory.GetByPrimaryKey怎么用?C# Factory.GetByPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Factory
的用法示例。
在下文中一共展示了Factory.GetByPrimaryKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnSave_Click
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
if (btnDelete.Enabled == false)
{
List<Factory> listFac = new List<Factory>();
listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList();
if (listFac.Count > 0)
{
RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");");
return;
}
Factory fac = new Factory();
fac.No = txtNo.Text;
fac.CompanyId = int.Parse(GetCompany());
fac.Name = txtName.Text;
fac.isDeleted = false;
//fac.ImageFile = txtImgName.Text;
fac.CreateAccount = fac.ModifiedAccount = this.User.Identity.Name;
int id = Factory.InsertWithIndentity(fac);
fac.ImageFile = id.ToString()+".png";
fac.Update();
string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, id, txtName.Text);
if (!Directory.Exists(Server.MapPath(pathNew))) //(!Directory.Exists(Server.MapPath("~/Portal\\Images\\Factory\\")))
{
Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)"));
}
string path = Server.MapPath(pathNew);//"~/Portal\\Images\\Factory\\");
//string filename = imgFactory.ImageUrl;
string base64 = (string)ViewState["img"];
byte[] b = Convert.FromBase64String(base64);
System.IO.File.WriteAllBytes(path + "/" + id +".png", b);
}
else
{
Factory fac = new Factory();
fac.FactoryId = int.Parse(hiddenFacID.Value);
fac.CompanyId = int.Parse(GetCompany());
fac = fac.GetByPrimaryKey();
if (fac.Name.Trim() != txtName.Text.Trim())
{
List<Factory> listFac = new List<Factory>();
listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList();
if (listFac.Count > 0)
{
RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");");
return;
}
}
fac.ModifiedAccount = this.User.Identity.Name;
fac.No = txtNo.Text;
fac.Name = txtName.Text;
fac.ImageFile = hiddenFacID.Value.ToString()+".png";
fac.Update();
string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, hiddenFacID.Value, txtName.Text);
if (!Directory.Exists(Server.MapPath(pathNew))) //("~/Portal\\Images\\Factory\\")))
{
Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)"));
}
string path = Server.MapPath(pathNew); //("~/Portal\\Images\\Factory\\");
if (ViewState["img"] != null)
{
string base64 = (string)ViewState["img"];
byte[] b = Convert.FromBase64String(base64);
System.IO.File.WriteAllBytes(path + "/" + int.Parse(hiddenFacID.Value) + ".png", b);
}
}
ViewState.Remove("img");
panelEdit.Visible = false;
panelMain.Visible = true;
Search();
}
catch (Exception ex)
{
RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");");
logger.Error("Erorr btnSave_click", ex);
}
}