Пример #1
0
        /// <summary>
        /// Returns a binary stream from the given SVG Image
        /// </summary>
        /// <param name="image">SVG image that has to be converted into a binary object.</param>
        /// <returns></returns>
        public static System.Data.Linq.Binary GetBinaryFromSvgImage(SvgImage image)
        {
            // If the input image is null, nothing has to be done
            if (image == null)
            {
                return(null);
            }

            System.Data.Linq.Binary binary = null;

            try
            {
                // Convert the image into a binary object using a MemoryStream and the SvgSerializer from DevExpress
                using (MemoryStream ms = new MemoryStream())
                {
                    SvgSerializer.SaveSvgImageToXML(ms, image);
                    binary = new System.Data.Linq.Binary(ms.GetBuffer());
                }
            }
            catch
            {
                binary = null;
            }

            return(binary);
        }
Пример #2
0
        private void btninsert_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofp = new OpenFileDialog();

            byte[] fileb = imgtoarray(pbfood.Image);
            System.Data.Linq.Binary filebi = new System.Data.Linq.Binary(fileb);
            string paths = txtpath.Text;
            //System.Data.Linq.Binary pathbi = new System.Data.Linq.Binary(paths);
            int menus  = Convert.ToInt32(txtmenuid.Text);
            int prices = Convert.ToInt32(txtprice.Text);
            var tabs   = new msmenu
            {
                menuid = menus,
                photo  = filebi,
                name   = txtmenun.Text,
                price  = prices,
                path   = txtpath.Text,
            };

            dbku.msmenus.InsertOnSubmit(tabs);
            dbku.SubmitChanges();
            MessageBox.Show("Successfull");

            this.bind();
            dgrid.Refresh();
        }
 public static void preAuthorizationTokenGeneration(string username, out string id, out long?internalId, out byte[] password, out byte[] salt)
 {
     id         = string.Empty;
     internalId = -1;
     System.Data.Linq.Binary _password = null;
     System.Data.Linq.Binary _salt     = null;
     password = new byte[] { };
     salt     = new byte[] { };
     if (username == "saharmerheb")
     {
         password = new byte[64] {
             137, 193, 82, 93, 47, 180, 86, 24, 157, 189, 86, 207, 197, 109, 122, 4, 199, 217, 164, 97, 68, 43, 24, 85, 252, 179, 79, 19, 9, 219, 147, 214, 38, 133, 76, 168, 157, 213, 91, 210, 146, 133, 58, 248, 157, 244, 171, 187, 162, 114, 178, 88, 7, 37, 76, 85, 75, 243, 129, 11, 219, 123, 245, 60
         };
         salt = new byte[256] {
             48, 12, 100, 9, 136, 224, 44, 9, 244, 252, 44, 63, 183, 66, 249, 110, 147, 65, 153, 232, 138, 0, 222, 164, 108, 57, 226, 100, 56, 236, 61, 12, 231, 178, 8, 56, 115, 187, 16, 255, 1, 150, 91, 206, 238, 173, 180, 120, 114, 2, 121, 196, 48, 196, 227, 93, 210, 232, 148, 54, 241, 135, 172, 136, 236, 50, 87, 101, 150, 19, 226, 60, 198, 9, 98, 106, 29, 137, 28, 202, 22, 57, 156, 33, 122, 222, 241, 46, 51, 174, 73, 215, 187, 0, 246, 107, 197, 37, 247, 17, 214, 224, 167, 172, 103, 205, 125, 57, 87, 245, 201, 102, 171, 245, 18, 121, 211, 126, 207, 245, 231, 96, 169, 156, 246, 112, 191, 87, 67, 185, 211, 139, 175, 116, 26, 40, 192, 62, 152, 92, 64, 110, 97, 140, 49, 86, 251, 220, 92, 191, 217, 1, 58, 155, 75, 174, 123, 182, 198, 29, 157, 190, 131, 199, 116, 187, 211, 72, 60, 136, 0, 58, 192, 26, 119, 223, 108, 202, 51, 208, 139, 135, 17, 95, 193, 18, 148, 130, 156, 166, 55, 109, 61, 178, 25, 219, 1, 194, 163, 198, 33, 179, 77, 153, 127, 7, 20, 122, 103, 102, 60, 165, 56, 186, 6, 202, 243, 240, 225, 206, 174, 205, 6, 249, 84, 162, 149, 240, 123, 200, 67, 31, 181, 28, 164, 175, 51, 20, 42, 111, 22, 197, 125, 211, 67, 49, 64, 198, 159, 232, 200, 251, 58, 84, 2, 201
         };
         id         = "5D8108B2-EEC2-4759-999B-2790909535E8";
         internalId = 1;
         return;
     }
     using (var dc = new DataClassesDataContext(ConnectionString))
     {
         dc.preAuthorizationTokenGeneration(username, ref id, ref internalId, ref _password, ref _salt);
         password = _password.ToArray();
         salt     = _salt.ToArray();
     }
 }
        private bool insertVendor()
        {
            DTO.ST_vendor newVendor = new DTO.ST_vendor();
            newVendor.vendor_name    = txt_VendorName.Text;
            newVendor.vendor_address = txt_Address.Text;
            newVendor.vendor_phone   = txt_PhoneNumber.Text;

            newVendor.vendor_bank_account_number = txt_BankAccountNumber.Text;



            DateTime now = DateTime.Now;

            now.ToString("yyyy/MM/dd");
            newVendor.vendor_created_date = now;

            newVendor.vendor_status = true;

            if (pic_Logo.Image != null)
            {
                byte[] fileByte = converImageToBirany(pic_Logo.Image);
                System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(fileByte);
                newVendor.vendor_image = fileBinary;
            }

            newVendor.employee_created = frm_Main.Vitual_id;

            return(vendorBus.insertVendor(newVendor));
        }
Пример #5
0
        public void InsertRegister(RegisterInfo reginfo)
        {
            try
            {
                using (RMSDataContext db = new RMSDataContext())
                {
                    Register reg = new Register();
                    Guid     id;
                    id           = Guid.NewGuid();
                    reg.ID       = id.ToString();
                    reg.UserName = reginfo.UserName;
                    reg.NRC      = reginfo.NRC;
                    reg.DOB      = reginfo.DOB;
                    System.Data.Linq.Binary file_binary = new System.Data.Linq.Binary(reginfo.Picture);
                    reg.Picture      = file_binary;
                    reg.Address      = reginfo.Address;
                    reg.Gender       = reginfo.Gender;
                    reg.Phone        = reginfo.Phone;
                    reg.Password     = reginfo.Password;
                    reg.Email        = reginfo.Email;
                    reg.InsertedDate = DateTime.UtcNow.AddMinutes(390);
                    reg.UpdatedDate  = DateTime.UtcNow.AddMinutes(390);

                    db.Registers.InsertOnSubmit(reg);
                    db.SubmitChanges();
                }
            }
            catch
            {
                Register a = new Register();
            }
        }
        private void btnSaveAccountAdmin_Click(object sender, EventArgs e)
        {
            if (checkDataAccountAdmin())
            {
                string statusAcc;
                if (lblStatusAdmin.BackColor == Color.Lime)
                {
                    statusAcc = "Activate";
                }
                else if (lblStatusAdmin.BackColor == Color.Red)
                {
                    statusAcc = "Lock";
                }
                else
                {
                    statusAcc = "Null";
                }

                byte[] Image_admin          = ImageToByteArray(picAvtAdmin.Image);
                System.Data.Linq.Binary img = new System.Data.Linq.Binary(Image_admin);

                Admin admin = new Admin();
                admin.MaAdmin  = lblIdAdmin.Text.Trim();
                admin.Password = txtPassAdmin.Text;
                //admin.Avt = img;
                admin.StatusAcc = statusAcc;
                adminService.UpadteAccount(admin);
                LoadAdminToDgv();
            }
        }
Пример #7
0
        private void bunifuFlatButton5_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext databaseConnection = new DataClasses1DataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\shadman\Desktop\RUBER\Assets\RMS\RMS\RMSDB.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                // Convert System.Drawing.Image to a byte[]
                byte[] file_byte = ImageToByteArray(editPicture.Image);
                // Create a System.Data.Linq.Binary - this is what an "image" column is mapped to
                System.Data.Linq.Binary file_binary = new System.Data.Linq.Binary(file_byte);

                //selectedmenu newmenu = new selectedmenu()
                //{
                //    img = file_binary,


                //};

                menu newmenu = databaseConnection.menus.Single(menus => menus.Id == Convert.ToInt32(label9.Text));

                newmenu.img = file_binary;



                newmenu.Name  = editName.Text;
                newmenu.Price = Convert.ToInt32(editPrice.Text);
                newmenu.Desc  = editDesc.Text;
            }
            finally
            {
                // Save
                databaseConnection.SubmitChanges();
                MessageBox.Show("Menu Item Added Successfully");
            }
        }
Пример #8
0
        private void bunifuFlatButton3_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext databaseConnection = new DataClasses1DataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\shadman\Desktop\RUBER\Assets\RMS\RMS\RMSDB.mdf;Integrated Security=True;Connect Timeout=30");

            try
            {
                // Convert System.Drawing.Image to a byte[]
                byte[] file_byte = ImageToByteArray(pictureBox1.Image);
                // Create a System.Data.Linq.Binary - this is what an "image" column is mapped to
                System.Data.Linq.Binary file_binary = new System.Data.Linq.Binary(file_byte);
                menu newmenu = new menu()
                {
                    img = file_binary,
                };

                newmenu.Name  = bunifuMaterialTextbox1.Text;
                newmenu.Price = int.Parse(bunifuMaterialTextbox2.Text);
                newmenu.Desc  = richTextBox1.Text;

                databaseConnection.menus.InsertOnSubmit(newmenu);
            }
            finally
            {
                // Save
                databaseConnection.SubmitChanges();
                MessageBox.Show("Menu Item Added Successfully");
            }
        }
Пример #9
0
        private bool updateBuildingContractor()
        {
            DTO.ST_building_contractor newBuildingContractor = new DTO.ST_building_contractor();
            newBuildingContractor.building_contractor_id                  = buildingContractorId;
            newBuildingContractor.building_contractor_name                = txt_BuildingContractorName.Text;
            newBuildingContractor.building_contractor_address             = txt_Address.Text;
            newBuildingContractor.building_contractor_phone               = txt_PhoneNumber.Text;
            newBuildingContractor.building_contractor_email               = txt_Email.Text;
            newBuildingContractor.building_contractor_bank_account_number = txt_BankAccountNumber.Text;
            newBuildingContractor.building_contractor_tax_code            = txt_Fax.Text;
            newBuildingContractor.building_contractor_description         = txt_Description.Text;
            if (txt_Liabilities.Text != "")
            {
                newBuildingContractor.building_contractor_liabilities = Convert.ToDecimal(txt_Liabilities.Text);
            }
            if (date_BirthDay.Text != "")
            {
                DateTime date = Convert.ToDateTime(date_BirthDay.Text);
                date.ToString("yyyy/MM/dd");
                newBuildingContractor.building_contractor_date_of_birth = date;
            }

            if (pic_Logo.Image != null)
            {
                byte[] fileByte = converImageToBirany(pic_Logo.Image);
                System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(fileByte);
                newBuildingContractor.building_contractor_image = fileBinary;
            }

            return(buildingContractorBus.updateBuildingContractor(newBuildingContractor));
        }
Пример #10
0
        }     // AddColumn

        // TODO: Конвертирует bitmap в двоичное значение
        public static System.Data.Linq.Binary BitmapToBinary(BitmapImage bmp)
        {
            MemoryStream ms = new MemoryStream(bmp.StreamSource.ReadByte());

            System.Data.Linq.Binary bin = new System.Data.Linq.Binary(ms.ToArray());
            return(bin);
        } // BitmapToBinary
Пример #11
0
 public Categories(int CategoryID, string CategoryName, string Description, System.Data.Linq.Binary Picture)
 {
     this._CategoryID = CategoryID;
     this._CategoryName = CategoryName;
     this._Description = Description;
     this._Picture = Picture;
 }
Пример #12
0
        public static Document GetNewInstance(int ArchiveDocumentID, System.Data.Linq.Binary Data)
        {
            Document _Instance = new Document();

            _Instance.ArchiveDocumentID = ArchiveDocumentID;
            _Instance.Data = Data;
            return(_Instance);
        }
Пример #13
0
        public static Image dbImgaeToImage(System.Data.Linq.Binary image)
        {
            byte[]       b   = image.ToArray();
            MemoryStream ms  = new MemoryStream(b);
            Image        img = Image.FromStream(ms);

            return(img);
        }
Пример #14
0
        } // public void impFactPOSDel()

        private void impFactPOSLinesDel(System.Data.Linq.Binary docIDRRef)
        {
            var chequeLns = from c in dataContext.FactPOSLines
                            where c.Document898_IDRRef == docIDRRef
                            select c;

            dataContext.FactPOSLines.DeleteAllOnSubmit(chequeLns);
        }
Пример #15
0
        } // public void impDocSalesDel()

        private void impDocSalesLinesDel(System.Data.Linq.Binary docIDRRef)
        {
            var dLns = from c in dataContext.DocSalesLines
                       where c.Document822_IDRRef == docIDRRef
                       select c;

            dataContext.DocSalesLines.DeleteAllOnSubmit(dLns);
        }
Пример #16
0
        public void TestNoDefaultConstructorBinary()
        {
            byte[] orig = new byte[20];
            new Random(123456).NextBytes(orig);
            var input  = new System.Data.Linq.Binary(orig);
            var output = connection.Query <NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;

            Assert.Equal(orig, output.ToArray());
        }
Пример #17
0
        private void impFactTransferFromProductionLinesDel(System.Data.Linq.Binary docIDRRef)
        {
            var chequeLns = from c in dataContext.DocTransferProductionLines
                            where c.Document741_IDRRef == docIDRRef &&
                            c.TransferType == false
                            select c;

            dataContext.DocTransferProductionLines.DeleteAllOnSubmit(chequeLns);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text != string.Empty && textBox3.Text != string.Empty && textBox4.Text != string.Empty && textBox5.Text != string.Empty && textBox6.Text != string.Empty && textBox7.Text != string.Empty && textBox8.Text != string.Empty && textBox9.Text != string.Empty && textBox10.Text != string.Empty)
            {
                if (radioButton1.Checked || radioButton2.Checked)
                {
                    Doctor_s_List a = new Doctor_s_List();
                    a.Id            = int.Parse(textBox1.Text);
                    a.Name          = textBox2.Text;
                    a.Date_Of_Birth = Convert.ToDateTime(textBox3.Text);
                    a.Date_Joined   = Convert.ToDateTime(textBox4.Text);
                    a.Designation   = textBox5.Text;
                    a.Specialty     = textBox6.Text;
                    a.Mobile_No_    = textBox7.Text;
                    a.Address       = textBox8.Text;
                    a.Username      = textBox9.Text;
                    a.Password      = textBox10.Text;

                    if (radioButton1.Checked)
                    {
                        a.Gender = "Male";
                    }
                    else
                    {
                        a.Gender = "Female";
                    }

                    try
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                            var binary = new System.Data.Linq.Binary(ms.GetBuffer());
                            a.Image = binary;
                        }

                        h.Doctor_s_Lists.InsertOnSubmit(a);
                        h.SubmitChanges();

                        MessageBox.Show("Registration Completed Successfully");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Registration error !! Please insert your information in proper way !!!");
                    }
                }
                else
                {
                    MessageBox.Show("Please select your Gender");
                }
            }
            else
            {
                MessageBox.Show("Please provide all Information");
            }
        }
        public void updateCustomer()
        {
            DTO.ST_customer updateCustomer = new DTO.ST_customer();
            updateCustomer.customer_id   = customerId;
            updateCustomer.customer_name = txt_CustomerName.Text;
            updateCustomer.custome_bank_account_number = txt_BankAccountNumber.Text;
            if (date_BirthDay.Text != "")
            {
                DateTime date = Convert.ToDateTime(date_BirthDay.Text);
                date.ToString("yy/MM/dd");
                updateCustomer.custome_date_of_birth = date;
            }
            var gender = cbb_Gender.SelectedItem;

            if (gender == "Nam")
            {
                updateCustomer.custome_gender = true;
            }
            else
            {
                updateCustomer.custome_gender = false;
            }

            updateCustomer.custome_phone         = txt_PhoneNumber.Text;
            updateCustomer.custome_tax_code      = txt_Fax.Text;
            updateCustomer.customer_address      = txt_Address.Text;
            updateCustomer.customer_created_date = DateTime.Now;
            updateCustomer.customer_description  = txt_Description.Text;
            updateCustomer.customer_email        = txt_Email.Text;
            updateCustomer.customer_liabilities  = txt_Liabilities.Text;
            updateCustomer.employee_created      = 1;


            // get value lookup edit customer group

            updateCustomer.customer_group_id = Convert.ToInt64(lke_CustomerGroup.EditValue);

            //get value picter customer pricter
            if (pic_Logo.Image != null)
            {
                byte[] fileByte = converImageToBirany(pic_Logo.Image);
                System.Data.Linq.Binary fileBinary = new System.Data.Linq.Binary(fileByte);
                updateCustomer.customer_image = fileBinary;
            }

            bool boolUpdateCustomer = customerBus.updateCustomer(updateCustomer);

            if (boolUpdateCustomer == true)
            {
                messeage.success("Chĩnh Sửa Thành Công!");
            }
            else
            {
                messeage.error("Không Thể Chĩnh Sửa!");
            }
        }
Пример #20
0
 private object NormalizeDbType(object value)
 {
     System.Data.Linq.Binary b = value as System.Data.Linq.Binary;
     // Mono 2.4.2.3's Binary.operator!= is bad; avoid it.
     if (!object.ReferenceEquals(b, null))
     {
         return(b.ToArray());
     }
     return(value);
 }
Пример #21
0
        public void TestLinqBinaryRaw()
        {
            byte[] orig = new byte[20];
            new Random(123456).NextBytes(orig);
            var input = new System.Data.Linq.Binary(orig);

            var output = connection.Query <System.Data.Linq.Binary>("select @input as [Value]", new { input }).First();

            Assert.Equal(orig, output.ToArray());
        }
Пример #22
0
        public void TestLinqBinaryToClass()
        {
            byte[] orig = new byte[20];
            new Random(123456).NextBytes(orig);
            var input = new System.Data.Linq.Binary(orig);

            var output = connection.Query <WithBinary>("select @input as [Value]", new { input }).First().Value;

            output.ToArray().IsSequenceEqualTo(orig);
        }
Пример #23
0
        private void them_Click(object sender, EventArgs e)
        {
            if (ho_ten.Text != "" && dia_chi.Text != "" && so_dien_thoai.Text != "" && hinh_anh.Text != "")
            {
                if (!utils.validate_PhoneNumberInput(so_dien_thoai.Text))
                {
                    MessageBox.Show("So dien thoai khong hop le!");
                    return;
                }
                GIAOVIEN gv = new GIAOVIEN();
                gv.tengv  = ho_ten.Text;
                gv.sdt    = so_dien_thoai.Text;
                gv.diachi = dia_chi.Text;
                gv.mamh   = bomon_dict[bo_mon.Items[bo_mon.SelectedIndex].ToString()];
                string sex = gioi_tinh.Items[gioi_tinh.SelectedIndex].ToString();
                if (sex == "Nam")
                {
                    gv.gt = true;
                }
                else
                {
                    gv.gt = false;
                }
                gv.ngaysinh   = ngay_sinh.Value;
                gv.ngayvaolam = ngay_vao_lam.Value;
                Image img = Image.FromFile(hinh_anh.Text);
                //convert image into linq.binary
                using (MemoryStream ms = new MemoryStream())
                {
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    var binary = new System.Data.Linq.Binary(ms.GetBuffer());
                    gv.hinhanh = binary;
                }
                gv.magv = utils.generatePrimaryKey("GV", GVtable.Rows.Count);

                // begin insert record
                frmLogin._database.GIAOVIENs.InsertOnSubmit(gv);
                try
                {
                    frmLogin._database.SubmitChanges();
                    GVtable.Rows.Add(gv.magv, gv.tengv, gv.gt, gv.ngaysinh, gv.ngayvaolam,
                                     bo_mon.Items[bo_mon.SelectedIndex].ToString(), gv.diachi, gv.sdt, img);
                }
                catch (Exception err)
                {
                    MessageBox.Show("Them du lieu loi " + err.Message);
                    Console.WriteLine(err.Message);
                }
            }
            else
            {
                //error
                MessageBox.Show("Mot so truong de trong, hay nhap vao!");
            }
        }
Пример #24
0
 public MusicGroup(string name = " ", string nationality = " ", TypeOfMusic type = 0, DateTime createdDate = new DateTime(), DateTime endDate = new DateTime(), System.Data.Linq.Binary image = null, System.Guid id = new Guid())
 {
     Name        = name;
     Nationality = nationality;
     Type        = type;
     CreatedDate = createdDate;
     EndDate     = endDate;
     Image       = image;
     ID          = id;
     _musicians  = new List <Musician>();
     _songs      = new List <Song>();
 }
Пример #25
0
 private byte[] convertirVarBinary(System.Data.Linq.Binary miVarBinary)
 {
     if (miVarBinary != null)
     {
         byte[] Foto = miVarBinary.ToArray();
         return(Foto);
     }
     else
     {
         return(null);
     }
 }
Пример #26
0
        public static string TimestampToString(this System.Data.Linq.Binary binary)
        {
            byte[] binarybytes = binary.ToArray();
            string result      = "";

            foreach (byte b in binarybytes)
            {
                result += b.ToString() + "|";
            }
            result = result.Substring(0, result.Length - 1);
            return(result);
        }
Пример #27
0
        internal static object DeserializeStringToObject(string val, Type valType, bool valueUri, SerializationFormatKind serializationKind)
        {
            object rehydratedObject = null;

            if (val == null)
            {
                rehydratedObject = null;
            }
            else
            {
                if (valueUri)
                {
                    if (valType == typeof(byte[]))
                    {
                        if (val != null)
                        {
                            return(new UTF8Encoding().GetBytes(val));
                        }
                        return(null);
                    }
#if !ClientSKUFramework
                    else if (valType == typeof(System.Data.Linq.Binary))
                    {
                        byte[] bytes = new UTF8Encoding().GetBytes(val);
                        System.Data.Linq.Binary binary = new System.Data.Linq.Binary(bytes);
                        return(binary);
                    }
#endif

                    else
                    {
                        rehydratedObject = AstoriaUnitTests.Data.TypeData.ObjectFromXmlValue(val, valType);
                    }
                }
                else if (serializationKind == SerializationFormatKind.JSON)
                {
                    //Special case that seems to be failing
                    if (valType == typeof(DateTime) && val.Equals("null", StringComparison.InvariantCulture))
                    {
                        rehydratedObject = null;
                    }
                    else
                    {
                        rehydratedObject = System.Data.Test.Astoria.Util.JsonPrimitiveTypesUtil.StringToPrimitive(val, valType);
                    }
                }
                else //xml
                {
                    rehydratedObject = AstoriaUnitTests.Data.TypeData.ObjectFromXmlValue(val, valType);
                }
            }
            return(rehydratedObject);
        }
Пример #28
0
        public static Image BinaryToImage(System.Data.Linq.Binary binaryData)
        {
            if (binaryData == null)
            {
                return(null);
            }

            byte[]       buffer    = binaryData.ToArray();
            MemoryStream memStream = new MemoryStream();

            memStream.Write(buffer, 0, buffer.Length);
            return(Image.FromStream(memStream));
        }
Пример #29
0
        public CheckImageModel GetImageForContribution(int imgId)
        {
            System.Data.Linq.Binary iBinary = (from i in CurrentImageDatabase.Others
                                               where i.Id == imgId
                                               select i.First).FirstOrDefault();

            CheckImageModel chkModel = new CheckImageModel
            {
                ImageId         = imgId,
                checkImageBytes = iBinary.ToArray()
            };

            return(chkModel);
        }
Пример #30
0
 public static System.Drawing.Image BinaryToImage(System.Data.Linq.Binary binary)
 {
     if (binary.Length > 0)
     {
         byte[]               b   = binary.ToArray();
         MemoryStream         ms  = new MemoryStream(b);
         System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
         return(img);
     }
     else
     {
         return(null);
     }
 }
Пример #31
0
        public byte[] Pasar(System.Data.Linq.Binary binary)
        {
            int cont = 1;

            byte[] img        = new byte[0];
            int    numOfBytes = binary.ToString().Length / 8;

            for (int j = 0; j < numOfBytes; j++)
            {
                img[j] = Convert.ToByte(binary.ToString().Substring(8 * j, 8), 2);
                cont++;
            }
            return(img);
        }
Пример #32
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            bool redir = true;

            if (FileUpload1.PostedFile.ContentLength <= 5 * 1024 * 1024 && FileUpload1.PostedFile.ContentLength > 0)
            {
                //System.Drawing.Image newbrokerimage = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);

                //newbrokerimage.Save( Server.MapPath("~/BrokerImages/") + Session["BrokerID"] + ".png", System.Drawing.Imaging.ImageFormat.Png);

                byte[] bytes = FileUpload1.FileBytes;

                bytes = imageResize.ResizeFromByteArray( 150, bytes, "test");

                System.Data.Linq.Binary image = new System.Data.Linq.Binary(bytes);

                ElectronicAppStorageDBDataContext eappstor = new ElectronicAppStorageDBDataContext();

                eappstor.uspDeleteBrokerImageByOwnerID((Guid)(Session["BrokerID"]));

                String filename = FileUpload1.FileName;
                String ext = filename.Substring( filename.LastIndexOf('.') + 1 );
                filename = filename.Substring( 0, filename.LastIndexOf('.'));

                eappstor.uspInsertBrokerImage(System.Guid.NewGuid(), (Guid)(Session["BrokerID"]), image, filename, ext);
            }
            else if (FileUpload1.PostedFile.ContentLength > 0)
            {
                redir = false;
                lblMessage.Text = "File must be less than 5MB in size.";
                lblMessage.Visible = true;
            }

            ElectronicAppDBDataContext ElectronicAppDB = new ElectronicAppDBDataContext();
            ElectronicAppDB.uspAlterBrokerInfo( (Guid)Session["BrokerID"], BrokerFirstName.Text, BrokerLastName.Text, BrokerEmail.Text, BrokerPhone.Text, BrokerFax.Text, BrokerAddress.Text, BrokerCity.Text, BrokerState.Text, BrokerZip.Text);

            if (redir)
            {
                Response.Redirect("Welcome.aspx", false);
            }
        }
Пример #33
0
 public void TestNoDefaultConstructorBinary()
 {
     byte[] orig = new byte[20];
     new Random(123456).NextBytes(orig);
     var input = new System.Data.Linq.Binary(orig);
     var output = connection.Query<NoDefaultConstructorWithBinary>("select @input as val", new { input }).First().Value;
     output.ToArray().IsSequenceEqualTo(orig);
 }
Пример #34
0
        public void TestLinqBinaryRaw()
        {
            byte[] orig = new byte[20];
            new Random(123456).NextBytes(orig);
            var input = new System.Data.Linq.Binary(orig);

            var output = connection.Query<System.Data.Linq.Binary>("select @input as [Value]", new { input }).First();

            output.ToArray().IsSequenceEqualTo(orig);
        }
Пример #35
0
        /// <summary>Selects a single resource by key values.</summary>
        /// <param name="queryExpression">Base query for resources</param>
        /// <param name="resourceType">resource type whose keys are specified</param>
        /// <param name="key">Key values for the given resource type.</param>
        /// <returns>A new query that selects the single resource that matches the specified key values.</returns>
        private static Expression SelectResourceByKey(Expression queryExpression, ResourceType resourceType, KeySegment key)
        {
            Debug.Assert(queryExpression != null, "queryExpression != null");
            Debug.Assert(key != null, "key != null");
            
            List<KeyValuePair<string, object>> keyValues = key.Keys.ToList();
            Debug.Assert(keyValues.Count != 0, "keyValues.Count != 0");
            Debug.Assert(resourceType.KeyProperties.Count == keyValues.Count, "resourceType.KeyProperties.Count == keyValues.Count");

            for (int i = 0; i < resourceType.KeyProperties.Count; i++)
            {
                ResourceProperty keyProperty = resourceType.KeyProperties[i];
                Debug.Assert(keyProperty.IsOfKind(ResourcePropertyKind.Key), "keyProperty.IsOfKind(ResourcePropertyKind.Key)");

                object keyValue;
                if (keyValues.Count == 0)
                {
                    keyValue = keyValues[0].Value;
                }
                else
                {
                    keyValue = keyValues.Single(v => v.Key == keyProperty.Name).Value;    
                }
                
                var binaryValue = keyValue as byte[];
                if (binaryValue != null && keyProperty.Type == typeof(System.Data.Linq.Binary))
                {
                    keyValue = new System.Data.Linq.Binary(binaryValue);
                }

                var stringValue = keyValue as string;
                if (stringValue != null && keyProperty.Type == typeof(XElement))
                {
                    keyValue = XElement.Parse(stringValue);
                }

                if (keyProperty.Type == typeof(DateTime))
                {
                    Debug.Assert(keyValue != null && keyValue is DateTimeOffset, "For DateTime properties, the value must be read as DateTimeOffset");
                    keyValue = WebUtil.ConvertDateTimeOffsetToDateTime((DateTimeOffset)keyValue);
                }

                ParameterExpression parameter = Expression.Parameter(queryExpression.ElementType(), "element");
                Expression e;
                if (keyProperty.CanReflectOnInstanceTypeProperty)
                {
                    e = Expression.Property(parameter, keyProperty.Name);
                }
                else
                {
                    e = Expression.Call(null /*instance*/, DataServiceProviderMethods.GetValueMethodInfo, parameter, Expression.Constant(keyProperty));
                    e = Expression.Convert(e, keyProperty.Type);
                }

                BinaryExpression body = Expression.Equal(e, Expression.Constant(keyValue));
                LambdaExpression predicate = Expression.Lambda(body, parameter);
                queryExpression = queryExpression.QueryableWhere(predicate);
            }

            return queryExpression;
        }
Пример #36
0
        /// <summary>
        /// Update the resource specified in the given request description
        /// </summary>
        /// <param name="description">description about the request uri</param>
        /// <param name="dataService">data service type to which the request was made</param>
        /// <param name="stream">Stream from which request body should be read.</param>
        /// <returns>The tracked modifications.</returns>
        internal static RequestDescription HandlePutRequest(RequestDescription description, IDataService dataService, Stream stream)
        {
            Debug.Assert(stream != null, "stream != null");
            Debug.Assert(dataService != null, "dataService != null");

            object requestValue = null;
            ContentFormat requestFormat;
            object entityGettingModified = null;
            ResourceSetWrapper container = null;
            string mimeType;
            Encoding encoding;
            DataServiceHostWrapper host = dataService.OperationContext.Host;
            HttpProcessUtility.ReadContentType(host.RequestContentType, out mimeType, out encoding);

            UpdateTracker tracker = UpdateTracker.CreateUpdateTracker(dataService);
            Debug.Assert(tracker != null, "Change tracker must always be created.");

            // If its a primitive value that is getting modified, then we need to use the text or binary
            // serializer depending on the mime type
            if (description.TargetKind == RequestTargetKind.OpenPropertyValue ||
                description.TargetKind == RequestTargetKind.PrimitiveValue)
            {
                string contentType;
                requestFormat = WebUtil.GetResponseFormatForPrimitiveValue(description.TargetResourceType, out contentType);
                if (!WebUtil.CompareMimeType(contentType, mimeType))
                {
                    if (description.TargetResourceType != null)
                    {
                        throw new DataServiceException(415, Strings.BadRequest_InvalidContentType(host.RequestContentType, description.TargetResourceType.Name));
                    }
                    else
                    {
                        throw new DataServiceException(415, Strings.BadRequest_InvalidContentTypeForOpenProperty(host.RequestContentType, description.ContainerName));
                    }
                }

                if (requestFormat == ContentFormat.Binary)
                {
                    byte[] propertyValue = ReadByteStream(stream);
                    if (description.Property != null && description.Property.Type == typeof(System.Data.Linq.Binary))
                    {
                        requestValue = new System.Data.Linq.Binary(propertyValue);
                    }
                    else
                    {
                        requestValue = propertyValue;
                    }
                }
                else
                {
                    Debug.Assert(requestFormat == ContentFormat.Text, "requestFormat == ContentFormat.Text");
                    Debug.Assert(encoding != null, "encoding != null");
                    StreamReader requestReader = new StreamReader(stream, encoding);
                    string propertyValue = Deserializer.ReadStringFromStream(requestReader);

                    if (description.Property != null && propertyValue != null)
                    {
                        try
                        {
                            // Convert the property value to the correct type
                            requestValue = WebConvert.StringToPrimitive((string)propertyValue, description.Property.Type);
                        }
                        catch (FormatException e)
                        {
                            throw DataServiceException.CreateBadRequestError(Strings.BadRequest_ErrorInConvertingPropertyValue(description.Property.Name, description.Property.Type), e);
                        }
                    }
                    else
                    {
                        // For open types, there is no conversion required. There is not enough information to do the conversion.
                        requestValue = propertyValue;
                    }
                }
            }
            else if (description.TargetKind == RequestTargetKind.MediaResource)
            {
                requestFormat = ContentFormat.Binary;
                requestValue = stream;
            }
            else
            {
                requestFormat = WebUtil.SelectRequestFormat(mimeType, description);
                using (Deserializer deserializer = Deserializer.CreateDeserializer(description, dataService, true /*update*/, tracker))
                {
                    if (description.LinkUri)
                    {
                        string uri = deserializer.GetLinkUriFromPayload();

                        // No need to check for null - if the uri in the payload is /Customer(1)/BestFriend,
                        // and the value is null, it means that the user wants to set the current link to null
                        // i.e. in other words, unbind the relationship.
                        object linkResource = deserializer.GetTargetResourceToBind(uri, true /*checkNull*/);
                        entityGettingModified = Deserializer.HandleBindOperation(description, linkResource, deserializer.Service, deserializer.Tracker);
                        container = description.LastSegmentInfo.TargetContainer;
                    }
                    else
                    {
                        requestValue = deserializer.ReadEntity(description);

                        if (requestValue == null &&
                            description.LastSegmentInfo.HasKeyValues &&
                            description.TargetSource == RequestTargetSource.EntitySet)
                        {
                            throw DataServiceException.CreateBadRequestError(Strings.BadRequest_CannotSetTopLevelResourceToNull(description.ResultUri.OriginalString));
                        }
                    }
                }
            }

            // Update the property value, if the request target is property
            if (!description.LinkUri && IsQueryRequired(description, requestValue, dataService.Provider))
            {
                // Get the parent entity and its container and the resource to modify
                object resourceToModify = GetResourceToModify(
                    description, dataService, false /*allowCrossReferencing*/, out entityGettingModified, out container, true /*checkETag*/);

                tracker.TrackAction(entityGettingModified, container, UpdateOperations.Change);

                Deserializer.ModifyResource(description, resourceToModify, requestValue, requestFormat, dataService);
            }

            tracker.FireNotifications();

            if (entityGettingModified == null)
            {
                entityGettingModified = requestValue;
                container = description.LastSegmentInfo.TargetContainer;
            }

            return RequestDescription.CreateSingleResultRequestDescription(description, entityGettingModified, container);
        }
Пример #37
0
        public static void Verify(Workspace w, ExpNode q, IEnumerable results, ResourceType resType, ComplexType cType, bool bCount)
        {
            long count = 0;
            if (bCount)
            {

                object[] args = new object[] { results };
                Type qorType = typeof(QueryOperationResponseWrapper<>).MakeGenericType(resType.ClientClrType);
                object qor = Activator.CreateInstance(qorType, args);

                PropertyInfo pi = qor.GetType().GetProperty("GetTotalCount");
                object i = pi.GetValue(qor, new object[] { });

                count = (long)i;

                LinqQueryBuilder lb = new LinqQueryBuilder(w);
                lb.CountingMode = true;
                lb.Build(q);

                object baselineElementsCount = CommonPayload.CreateList(lb.QueryResult).Count;
                AstoriaTestLog.IsTrue(count == Convert.ToInt64(baselineElementsCount), "Count is different.Count is " + count.ToString() + ". Baseline count is " + baselineElementsCount.ToString());
            }

            LinqQueryBuilder linqBuilder = new LinqQueryBuilder(w);
            linqBuilder.Build(q);

            IQueryable baselines = linqBuilder.QueryResult;

            IEnumerator b = null;

            IEnumerator r = null;

            try
            {
                b = TrustedMethods.IQueryableGetEnumerator(baselines);
                r = results.GetEnumerator();
            }
            catch (InvalidOperationException invalidOperation)
            {
                if (!AstoriaTestProperties.IsRemoteClient)
                    throw invalidOperation;
            }

            PropertyInfo propertyInfo = null;
            Object expectedResult1 = null;
            Object expectedResult2 = null;

            try
            {
                while (b.MoveNext() && r.MoveNext())
                {
                    if (b.Current == null)
                    {
                        return;
                    }

                    if (r.Current == null)
                    {
                        throw new TestFailedException("Less results than expected");

                    }
                    //skip verification for Binary data type for Linq to Sql
                    if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && b.Current is System.Byte[])
                        return;

                    if (b.Current is System.Byte[])
                    {
                        byte[] newBase = (byte[])b.Current;
                        byte[] newAct = (byte[])r.Current;

                        if (newBase.Length != newAct.Length)
                            throw new TestFailedException("Failed to compare the results!");
                    }
#if !ClientSKUFramework

                    else if (b.Current is System.Data.Linq.Binary)
                    {
                        System.Data.Linq.Binary newBase = (System.Data.Linq.Binary)b.Current;
                        System.Data.Linq.Binary newAct = new System.Data.Linq.Binary((byte[])r.Current);

                        if (newBase.Length != newAct.Length)
                            throw new TestFailedException("Failed to compare the results!");

                    }
#endif

                    else if (b.Current is System.Xml.Linq.XElement)
                    {
                        if (b.Current.ToString() != r.Current.ToString())
                            throw new TestFailedException("Failed to compare the results!");
                    }
                    else
                    {
                        if (!b.Current.Equals(r.Current))
                        {
                            if (cType != null)
                            {
                                foreach (ResourceProperty property in cType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        propertyInfo = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyInfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyInfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
					    #if !ClientSKUFramework

                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
					    #endif


                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                foreach (ResourceProperty property in resType.Properties)
                                {
                                    if (!property.IsNavigation && !property.IsComplexType && !(property.Type is CollectionType))
                                    {
                                        //skip verification for Binary data type for Linq to Sql
                                        if (AstoriaTestProperties.DataLayerProviderKinds[0] == DataLayerProviderKind.LinqToSql && property.Type.Name == "LinqToSqlBinary")
                                            return;

                                        propertyInfo = b.Current.GetType().GetProperty(property.Name);
                                        expectedResult1 = propertyInfo.GetValue(b.Current, null);

                                        PropertyInfo propertyinfo2 = r.Current.GetType().GetProperty(property.Name);
                                        expectedResult2 = propertyinfo2.GetValue(r.Current, null);

                                        if (expectedResult1 != expectedResult2)
                                        {
                                            if (expectedResult1 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult1 = ((System.Xml.Linq.XElement)expectedResult1).ToString(System.Xml.Linq.SaveOptions.None);
                                            }

                                            if (expectedResult2 is System.Xml.Linq.XElement)
                                            {
                                                expectedResult2 = ((System.Xml.Linq.XElement)expectedResult2).ToString(System.Xml.Linq.SaveOptions.None);
                                            }
					    #if !ClientSKUFramework
                                            if (expectedResult1 is byte[])
                                            {
                                                expectedResult1 = new System.Data.Linq.Binary((byte[])expectedResult1);
                                            }

                                            if (expectedResult2 is byte[])
                                            {
                                                expectedResult2 = new System.Data.Linq.Binary((byte[])expectedResult2);
                                            }
					    #endif
                                            AstoriaTestLog.AreEqual(expectedResult1, expectedResult2, String.Format("Resource value for {0} does not match", property.Name), false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                AstoriaTestLog.WriteLine(e.ToString());
                throw;
            }
        }
Пример #38
0
        internal static object StringToPrimitive(string text, Type targetType)
        {
            Debug.Assert(text != null, "text != null");
            Debug.Assert(targetType != null, "targetType != null");

            object targetValue = null;
            targetType = Nullable.GetUnderlyingType(targetType) ?? targetType;

            if (typeof(String) == targetType)
            {
                targetValue = text;
            }
            else if (typeof(Boolean) == targetType)
            {
                targetValue = XmlConvert.ToBoolean(text);
            }
            else if (typeof(Byte) == targetType)
            {
                targetValue = XmlConvert.ToByte(text);
            }
            else if (typeof(byte[]) == targetType)
            {
                targetValue = Convert.FromBase64String(text);
            }
            else if (typeof(System.Data.Linq.Binary) == targetType)
            {
                targetValue = new System.Data.Linq.Binary(Convert.FromBase64String(text));
            }
            else if (typeof(SByte) == targetType)
            {
                targetValue = XmlConvert.ToSByte(text);
            }
            else if (typeof(DateTime) == targetType)
            {
                targetValue = XmlConvert.ToDateTime(text, XmlDateTimeSerializationMode.RoundtripKind);
            }
            else if (typeof(Decimal) == targetType)
            {
                targetValue = XmlConvert.ToDecimal(text);
            }
            else if (typeof(Double) == targetType)
            {
                targetValue = XmlConvert.ToDouble(text);
            }
            else if (typeof(Guid) == targetType)
            {
                targetValue = new Guid(text);
            }
            else if (typeof(Int16) == targetType)
            {
                targetValue = XmlConvert.ToInt16(text);
            }
            else if (typeof(Int32) == targetType)
            {
                targetValue = XmlConvert.ToInt32(text);
            }
            else if (typeof(Int64) == targetType)
            {
                targetValue = XmlConvert.ToInt64(text);
            }
            else if (typeof(System.Xml.Linq.XElement) == targetType)
            {
                targetValue = System.Xml.Linq.XElement.Parse(text, System.Xml.Linq.LoadOptions.PreserveWhitespace);
            }
            else
            {
                Debug.Assert(typeof(Single) == targetType, "typeof(Single) == targetType(" + targetType + ")");
                targetValue = XmlConvert.ToSingle(text);
            }

            return targetValue;
        }
Пример #39
0
 public Employees(int EmployeeID, string LastName, string FirstName, string Title, string TitleOfCourtesy, System.DateTime? BirthDate, System.DateTime? HireDate, string Address, string City, string Region, string PostalCode, string Country, string HomePhone, string Extension, System.Data.Linq.Binary Photo, string Notes, int? ReportsTo, string PhotoPath)
 {
     this._EmployeeID = EmployeeID;
     this._LastName = LastName;
     this._FirstName = FirstName;
     this._Title = Title;
     this._TitleOfCourtesy = TitleOfCourtesy;
     this._BirthDate = BirthDate;
     this._HireDate = HireDate;
     this._Address = Address;
     this._City = City;
     this._Region = Region;
     this._PostalCode = PostalCode;
     this._Country = Country;
     this._HomePhone = HomePhone;
     this._Extension = Extension;
     this._Photo = Photo;
     this._Notes = Notes;
     this._ReportsTo = ReportsTo;
     this._PhotoPath = PhotoPath;
 }
Пример #40
0
 public static bool BinaryCompare(byte[] binary,string str)
 {
     System.Data.Linq.Binary bin = new System.Data.Linq.Binary(binary);
     return string.Equals(bin.ToString(), str);
 }
Пример #41
0
        public static string Binary2String(byte[] binary)
        {
            System.Data.Linq.Binary bin = new System.Data.Linq.Binary(binary);

            string s=bin.ToString();
            return s;
            //return s.Substring(1,s.Length-2);//bin.tostring= \"AAAXXX\"
        }