Example #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int[] intRowindexarray = Grid1.SelectedRowIndexArray;

            if (intRowindexarray.Length > 0)
            {
                pd_standardkit sk    = new pd_standardkit();
                object[]       keys  = Grid1.DataKeys[intRowindexarray[0]];
                string         strID = keys[0].ToString();

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("isdelid", "2");
                string photoID = sk.getPhotoID(strID);
                if (photoID != "")
                {
                    // 返回与指定虚拟路径相对应的物理路径即绝对路径
                    string filePath = Server.MapPath(IMAGEPATH + sk.getPhotoFileName(strID));
                    // 删除该文件
                    System.IO.File.Delete(filePath);
                    int intresultPhoto = new pd_photo().delete("pd_photo", "ID", sk.getPhotoID(strID));
                }
                int intresult = sk.delete("pd_standardkit", "ID", strID);

                setPageContent(1);

                Alert alert = new Alert();

                if (intresult > 0)
                {
                    alert.Icon    = Icon.Information;
                    alert.Message = "成功移除数据";
                }
                else
                {
                    alert.MessageBoxIcon = MessageBoxIcon.Error;
                    alert.Message        = "数据移除失败";
                }


                alert.Show();
            }
            else
            {
                Alert.Show("请选择记录!");
            }
        }
Example #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> dicStandardkit = initDatadicStandardkit();
            Dictionary <string, string> dicPhoto       = initDatadicPhoto();
            string         strID           = editID.Text.ToString().Trim();
            pd_standardkit sk              = new pd_standardkit();
            pd_photo       ph              = new pd_photo();
            int            intresultRecord = 0;
            int            intresultPhoto  = 0;

            if (strID == "")
            {
                string standardKitID = Guid.NewGuid().ToString();
                dicStandardkit.Add("ID", standardKitID);
                dicStandardkit.Add("isdelid", "1");
                dicPhoto.Add("ID", Guid.NewGuid().ToString());
                dicPhoto.Add("isdelid", "1");
                dicPhoto.Add("pid", standardKitID);
                string str_scode = dicStandardkit["scode"].ToString().Trim();
                string str_sname = dicStandardkit["sname"].ToString().Trim();
                if ((sk.isExistdata("pd_standardkit", "scode", str_scode, "scode").Trim() != "") || (sk.isExistdata("pd_standardkit", "sname", str_sname, "sname").Trim() != ""))
                {
                    Alert.Show(" 标准件名称或代码已经存在!");
                }
                else
                {
                    intresultRecord = sk.add(dicStandardkit, "pd_standardkit");
                    intresultPhoto  = 1;
                    if ((filePhoto.HasFile) && (intresultRecord == 1))
                    {
                        intresultPhoto = ph.add(dicPhoto, "pd_photo");
                    }
                }
            }
            else
            {
                intresultRecord = sk.update(dicStandardkit, "pd_standardkit", "ID", strID);
                //exist photo->update || else ->add
                string photoID = sk.getPhotoID(strID).Trim();
                if (intresultRecord == 1)
                {
                    if (photoID != "")

                    {
                        // 返回与指定虚拟路径相对应的物理路径即绝对路径
                        string filePath = Server.MapPath(IMAGEPATH + sk.getPhotoFileName(strID));
                        // 删除该文件
                        System.IO.File.Delete(filePath);
                        intresultPhoto = ph.update(dicPhoto, "pd_photo", "ID", photoID);
                    }
                    else
                    {
                        dicPhoto.Add("ID", Guid.NewGuid().ToString());
                        dicPhoto.Add("isdelid", "1");
                        dicPhoto.Add("pid", strID);
                        intresultPhoto = ph.add(dicPhoto, "pd_photo");
                    }
                }
            }

            if (CurPage.Text.Trim() == "")
            {
                setPageContent(1);
            }
            else
            {
                setPageContent(5);
            }

            Alert alert = new Alert();

            if ((intresultRecord == 1) && (intresultPhoto == 1))
            {
                alert.Icon    = Icon.Information;
                alert.Message = "数据保存成功";
                imgPhoto.Reset();
                filePhoto.Reset();
            }
            else if (intresultRecord == 0)
            {
                alert.MessageBoxIcon = MessageBoxIcon.Error;
                alert.Message        = "数据保存失败";
                filePhoto.Reset();
                imgPhoto.Reset();
            }
            else if (intresultPhoto == 0)
            {
                alert.MessageBoxIcon = MessageBoxIcon.Error;
                alert.Message        = "图片保存失败";
                filePhoto.Reset();
                imgPhoto.Reset();
            }


            alert.Show();
        }