當前位置: 首頁>>代碼示例>>C#>>正文


C# Factory.GetByPrimaryKey方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:dtafe,項目名稱:WorkNC,代碼行數:82,代碼來源:MstFactory.aspx.cs


注:本文中的System.Factory.GetByPrimaryKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。